Part Number Hot Search : 
MAX116 P18CA LM393 RB160 MPS3706 AQW210 2SA2028G 97602E3
Product Description
Full Text Search
 

To Download AN21XX Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  cypress semiconductor 3901 north first street san jose, ca 95134 tel.: (800) 858-1810 (toll-free in the u.s.) (408) 943-2600 www.cypress.com ez-usb manual technical reference
cypress disclaimer agreement the information in this document is subject to change without notice and should not be con- strued as a commitment by cypress semicon- ductor corporation incorporated. while reasonable precautions have been taken, cypress semiconductor corporation assumes no responsibility for any errors that may appear in this document. no part of this document may be copied or reproduced in any form or by any means with- out the prior written consent of cypress semi- conductor corporation. cypress semiconductor products are not designed, intended, or authorized for use as components in systems intended for surgical implant into the body, or other applications intended to support or sustain life, or for any other application in which the failure of the cypress semiconductor product could create a situation where personal injury or death may occur. should buyer purchase or use cypress semiconductor products for any such unin- tended or unauthorized application, buyer shall indemnify and hold cypress semiconductor and its officers, employees, subsidiaries, affili- ates and distributors harmless against all claims, costs, damages, expenses, and rea- sonable attorney fees arising out of, directly or indirectly, any claim of personal injury or death associated with such unintended or unautho- rized use, even if such claim alleges that cypress semiconductor was negligent regard- ing the design or manufacture of the product. the acceptance of this document will be con- strued as an acceptance of the foregoing con- ditions. e z - u s b t e c hn i c a l r e fe r en c e m anu a l, v e r s i o n 1 . 1 0 copyright ? 2000, 2001, 2002 cypress semiconductor corporation all rights reserved. list of trademarks cypress, the cypress logo, ez-usb, making usb universal, xcelerator, and renumeration are trademarks or registered trademarks of cypress semiconductor corporation. macintosh is a regis- tered trademark of apple computer, inc. windows is a registered trademark of microsoft corpora- tion. i2c is a registered trademark of philips electronics. all other product or company names used in this manual may be trademarks, registered trademarks, or servicemarks of their respective own- ers.
i table of contents chapter 1. introducing ez-usb 1.1 introduction............................................................................................................. .......................1-1 1.2 ez-usb block diagrams .................................................................................................... ...........1-2 1.3 the usb specification .................................................................................................... ..............1-3 1.4 tokens and pids.......................................................................................................... .................1-3 1.5 host is master ........................................................................................................... ....................1-5 1.5.1 receiving data from the host......................................................................................... .1-5 1.5.2 sending data to the host............................................................................................. ....1-6 1.6 usb direction............................................................................................................ ....................1-6 1.7 frame .................................................................................................................... ........................1-6 1.8 ez-usb transfer types .................................................................................................... ............1-6 1.8.1 bulk transfers....................................................................................................... ...........1-6 1.8.2 interrupt transfers .................................................................................................. .........1-7 1.8.3 isochronous transfers ................................................................................................ .....1-7 1.8.4 control transfers .................................................................................................... .........1-8 1.9 enumeration .............................................................................................................. ....................1-8 1.10 the usb core ............................................................................................................ .................1-9 1.11 ez-usb microprocessor................................................................................................... .........1-10 1.12 renumeration?........................................................................................................... .............1-11 1.13 ez-usb endpoints ........................................................................................................ ............1-11 1.13.1 ez-usb bulk endpoints............................................................................................... 1-12 1.13.2 ez-usb control endpoint zero ...................................................................................1-12 1.13.3 ez-usb interrupt endpoints ........................................................................................1- 12 1.13.4 ez-usb isochronous endpoints ..................................................................................1-13 1.14 fast transfer modes ..................................................................................................... ............1-13 1.15 interrupts .............................................................................................................. .....................1-13 1.16 reset and power management.............................................................................................. ...1-14 1.17 ez-usb product family ................................................................................................... .........1-15 1.18 pin descriptions ........................................................................................................ ................1-15 chapter 2. ez-usb cpu 2.1 introduction............................................................................................................. .......................2-1 2.2 8051 enhancements ........................................................................................................ .............2-1 2.3 ez-usb enhancements ...................................................................................................... ..........2-2 2.4 ez-usb register interface................................................................................................ ............2-2 2.5 ez-usb internal ram ...................................................................................................... .............2-3
ii table of contents (table of contents) 2.6 i/o ports ................................................................................................................ ........................2-3 2.7 interrupts ............................................................................................................... ........................2-5 2.8 power control ............................................................................................................ ...................2-5 2.9 sfrs ..................................................................................................................... ........................2-6 2.10 internal bus ............................................................................................................ .....................2-7 2.11 reset................................................................................................................... ........................2-8 chapter 3. ez-usb memory 3.1 introduction ............................................................................................................. ......................3-1 3.2 8051 memory .............................................................................................................. ..................3-2 3.3 expanding ez-usb memory .................................................................................................. .......3-4 3.4 cs# and oe# signals ...................................................................................................... .............3-5 chapter 4. ez-usb input/output 4.1 introduction ............................................................................................................. ......................4-1 4.2 io ports ................................................................................................................. ........................4-2 4.3 io port registers........................................................................................................ ...................4-5 4.4 i2c controller ........................................................................................................... .....................4-6 4.5 8051 i2c controller ...................................................................................................... .................4-6 4.6 control bits............................................................................................................. .......................4-8 4.6.1 start................................................................................................................ .............4-8 4.6.2 stop................................................................................................................. ..............4-8 4.6.3 lastrd ............................................................................................................... ...........4-9 4.7 status bits .............................................................................................................. .......................4-9 4.7.1 done ................................................................................................................. .............4-9 4.7.2 ack .................................................................................................................. ...............4-9 4.7.3 berr................................................................................................................. ..............4-9 4.7.4 id1, id0 ............................................................................................................. ............4-10 4.8 sending i2c data......................................................................................................... ...............4-10 4.9 receiving i2c data ....................................................................................................... ..............4-10 4.10 i2c boot loader ......................................................................................................... ...............4-11 chapter 5. ez-usb enumeration and renumeration? 5.1 introduction ............................................................................................................. ......................5-1 5.2 the default usb device ................................................................................................... ............5-2 5.3 ez-usb core response to ep0 device requests .......................................................................5-3 5.4 firmware load ............................................................................................................ ..................5-5 5.5 enumeration modes ........................................................................................................ ..............5-6 5.6 no serial eeprom......................................................................................................... ..............5-7 5.7 serial eeprom present, first byte is 0xb0 ................................................................................ .5-8
table of contents iii (table of contents) 5.8 serial eeprom present, first byte is 0xb2 ................................................................................ .5-9 5.9 renumeration? ............................................................................................................ ................5-10 5.10 multiple renumerations? ................................................................................................. ..........5-11 5.11 default descriptor...................................................................................................... ................5-12 chapter 6. ez-usb bulk transfers 6.1 introduction............................................................................................................. .......................6-1 6.2 bulk in transfers........................................................................................................ ...................6-4 6.3 interrupt transfers...................................................................................................... ...................6-5 6.4 ez-usb bulk in example................................................................................................... ...........6-5 6.5 bulk out transfers....................................................................................................... ................6-6 6.6 endpoint pairing ......................................................................................................... ...................6-8 6.7 paired in endpoint status ................................................................................................ .............6-9 6.8 paired out endpoint status ............................................................................................... ..........6-9 6.9 using bulk buffer memory................................................................................................. ..........6-10 6.10 data toggle control ..................................................................................................... .............6-11 6.11 polled bulk transfer example ............................................................................................ .......6-12 6.12 enumeration note ........................................................................................................ .............6-13 6.13 bulk endpoint interrupts ................................................................................................ ............6-13 6.14 interrupt bulk transfer example......................................................................................... .......6-15 6.15 enumeration note ........................................................................................................ .............6-19 6.16 the autopointer......................................................................................................... ................6-20 chapter 7. ez-usb endpoint zero 7.1 introduction............................................................................................................. .......................7-1 7.2 control endpoint ep0..................................................................................................... ...............7-2 7.3 usb requests............................................................................................................. ..................7-5 7.3.1 get status........................................................................................................... .............7-6 7.3.2 set feature .......................................................................................................... ..........7-10 7.3.3 clear feature........................................................................................................ .........7-11 7.3.4 get descriptor....................................................................................................... .........7-12 7.3.4.1 get descriptor-device ........................................................................................7-14 7.3.4.2 get descriptor-configuration .............................................................................7-15 7.3.4.3 get descriptor-string .........................................................................................7-15 7.3.5 set descriptor ....................................................................................................... .........7-16 7.3.6 set configuration .................................................................................................... .......7-18 7.3.7 get configuration.................................................................................................... .......7-18 7.3.8 set interface ........................................................................................................ ..........7-19 7.3.9 get interface ........................................................................................................ ..........7-20 7.3.10 set address ......................................................................................................... ........7-20 7.3.11 sync frame .......................................................................................................... .......7-21 7.3.12 firmware load....................................................................................................... ......7-22
iv table of contents (table of contents) chapter 8. ez-usb isochronous transfers 8.1 introduction ............................................................................................................. ......................8-1 8.2 isochronous in transfers................................................................................................. .............8-2 8.2.1 initialization....................................................................................................... ...............8-2 8.2.2 in data transfers .................................................................................................... ........8-3 8.3 isochronous out transfers................................................................................................ ..........8-3 8.3.1 initialization....................................................................................................... ...............8-4 8.3.2 out data transfer .................................................................................................... ......8-5 8.4 setting isochronous fifo sizes ........................................................................................... ........8-5 8.5 isochronous transfer speed............................................................................................... ..........8-8 8.6 fast transfers ........................................................................................................... ....................8-9 8.6.1 fast writes .......................................................................................................... ..........8-10 8.6.2 fast reads ........................................................................................................... .........8-10 8.7 fast transfer timing ..................................................................................................... ..............8-11 8.7.1 fast write waveforms ................................................................................................. ..8-12 8.7.2 fast read waveforms.................................................................................................. .8-13 8.8 fast transfer speed ...................................................................................................... .............8-14 8.9 other isochronous registers .............................................................................................. ........8-15 8.9.1 disable iso .......................................................................................................... .........8-15 8.9.2 zero byte count bits ................................................................................................. ....8-16 8.10 iso in response with no data............................................................................................ .....8-16 8.11 using the isochronous fifos ............................................................................................. ......8-17 chapter 9. ez-usb interrupts 9.1 introduction ............................................................................................................. ......................9-1 9.2 usb core interrupts...................................................................................................... ................9-2 9.3 wakeup interrupt......................................................................................................... ..................9-2 9.4 usb signaling interrupts................................................................................................. ..............9-3 9.5 sutok, sudav interrupts .................................................................................................. .........9-8 9.6 sof interrupt ............................................................................................................ ....................9-8 9.7 suspend interrupt........................................................................................................ ..................9-9 9.8 usb reset interrupt ...................................................................................................... .............9-9 9.9 bulk endpoint interrupts................................................................................................. ...............9-9 9.10 usb autovectors......................................................................................................... ................9-9 9.11 autovector coding....................................................................................................... ..............9-11 9.12 i 2 c interrupt.................................................................................................................... ...........9-12 9.13 i 2 c registers.................................................................................................................... .........9-13
table of contents v (table of contents) chapter 10. ez-usb resets 10.1 introduction............................................................................................................ ....................10-1 10.2 ez-usb power-on reset (por) ............................................................................................. .10-1 10.3 releasing the 8051 reset ................................................................................................ .........10-3 10.3.1 ram download........................................................................................................ ....10-4 10.3.2 eeprom load ......................................................................................................... ...10-4 10.3.3 external rom ........................................................................................................ ......10-4 10.4 8051 reset effects ...................................................................................................... ..............10-4 10.5 usb bus reset ........................................................................................................... ..............10-6 10.6 ez-usb disconnect ....................................................................................................... ...........10-7 10.7 reset summary........................................................................................................... ..............10-8 chapter 11. ez-usb power management 11.1 introduction............................................................................................................ ....................11-1 11.2 suspend ................................................................................................................. ...................11-2 11.3 resume .................................................................................................................. ...................11-3 11.4 remote wakeup........................................................................................................... .............11-4 chapter 12. ez-usb registers 12.1 introduction............................................................................................................ ....................12-1 12.2 bulk data buffers ....................................................................................................... ...............12-3 12.3 isochronous data fifos .................................................................................................. .........12-4 12.4 isochronous byte counts ................................................................................................. .........12-5 12.5 cpu registers........................................................................................................... ................12-6 12.6 port configuration ...................................................................................................... ...............12-7 12.7 input-output port registers............................................................................................. ..........12-9 12.8 isochronous control/status registers.................................................................................... .12-11 12.9 i 2 c registers .................................................................................................................... .......12-13 12.10 interrupts ............................................................................................................. ..................12-15 12.11 endpoint 0 control and status registers ..............................................................................12 -21 12.12 endpoint 1-7 control and status registers ...........................................................................12- 22 12.13 global usb registers ................................................................................................... ........12-28 12.14 fast transfers ......................................................................................................... ..............12-34 12.15 setup data............................................................................................................. .............12-36 12.16 isochronous fifo sizes................................................................................................. .......12-37
vi table of contents (table of contents) chapter 13. ez-usb ac/dc parameters 13.1 electrical characteristics .............................................................................................. .............13-1 13.1.1 absolute maximum ratings.........................................................................................13- 1 13.1.2 operating conditions................................................................................................ ...13-1 13.1.3 dc characteristics.................................................................................................. .....13-1 13.1.4 ac electrical characteristics ....................................................................................... 13-2 13.1.5 general memory timing ..............................................................................................1 3-2 13.1.6 program memory read ...............................................................................................13 -2 13.1.7 data memory read .................................................................................................... .13-2 13.1.8 data memory write................................................................................................... ...13-3 13.1.9 fast data write..................................................................................................... .......13-3 13.1.10 fast data read ..................................................................................................... ....13-3 chapter 14. ez-usb packaging 14.1 44-pin pqfp package ..................................................................................................... .........14-1 14.2 80-pin pqfp package ..................................................................................................... .........14-3 14.3 48-pin tqfp package ..................................................................................................... .........14-5 appendix a cpu introduction a.1 introduction .............................................................................................................. .................. a - 1 a.2 8051 enhancements ......................................................................................................... ......... a - 2 a.3 performance overview ...................................................................................................... ........ a - 2 a.4 software compatibility .................................................................................................... ........... a - 4 a.5 803x/805x feature comparison .............................................................................................. .. a - 4 a.6 ez-usb/ds80c320 differences ............................................................................................... . a - 4 a.6.1 serial ports ............................................................................................................ ......... a - 5 a.6.2 timer 2 ................................................................................................................. .......... a - 5 a.6.3 timed access protection ............................................................................................... a - 5 a.6.4 watchdog timer .......................................................................................................... ... a - 5 a.6.5 power fail detection .................................................................................................... .. a - 5 a.6.6 port i/o ................................................................................................................ ........... a - 5 a.6.7 interrupts .............................................................................................................. .......... a - 6 a.7 ez-usb register interface ................................................................................................. ....... a - 6 a.8 ez-usb internal ram ....................................................................................................... ......... a - 6 a.9 i/o ports ................................................................................................................. .................... a - 7 a.10 interrupts ............................................................................................................... ................... a - 7 a.11 power control ............................................................................................................ .............. a - 8 a.12 special function registers (sfr) ......................................................................................... .. a - 8 a.13 external address/data buses .............................................................................................. .. a - 12 a.14 reset .................................................................................................................... ................. a - 12
table of contents vii (table of contents) appendix b cpu architectural overview b.1 internal data ram ......................................................................................................... .......... b - 13 b.1.1 the lower 128 ........................................................................................................... .. b - 13 b.1.2 the upper 128 ........................................................................................................... .. b - 14 b.1.3 sfr (special function register) space ....................................................................... b - 14 b.2 instruction set ........................................................................................................... ............... b - 14 b.2.1 instruction timing ...................................................................................................... ... b - 19 b.2.2 stretch memory cycles (wait states) .......................................................................... b - 19 b.2.3 dual data pointers ...................................................................................................... . b - 20 b.2.4 special function registers ........................................................................................... b - 21 appendix c ez-usb peripherals c.1 introduction .............................................................................................................. ................ c - 23 c.2 timers/counters ........................................................................................................... ........... c - 23 c.2.1 803x/805x compatibility ............................................................................................... c - 23 c.2.2 timers 0 and 1 .......................................................................................................... ... c - 24 c.2.2.1 mode 0, 13-bit timer/counter ? timer 0 and timer 1 ................................. c - 24 c.2.2.2 mode 1, 16-bit timer/counter ? timer 0 and timer 1 ................................. c - 25 c.2.2.3 mode 2, 8-bit counter with auto-reload ? timer 0 and timer 1 ................. c - 27 c.2.2.4 mode 3, two 8-bit counters ? timer 0 only ................................................ c - 28 c.2.3 timer rate control ...................................................................................................... . c - 29 c.2.4 timer 2 ................................................................................................................. ........ c - 30 c.2.4.1 timer 2 mode control .................................................................................... c - 31 c.2.5 timer 2 ? 16-bit timer/counter mode ........................................................................ c - 32 c.2.5.1 timer 2 ? 16-bit timer/counter mode with capture .................................... c - 32 c.2.6 timer 2 ? 16-bit timer/counter mode with auto-reload ............................................ c - 32 c.2.7 timer 2 ? baud rate generator mode ....................................................................... c - 33 c.3 serial interface .......................................................................................................... ............... c - 34 c.3.1 803x/805x compatibility ............................................................................................... c - 35 c.3.2 mode 0 .................................................................................................................. ....... c - 36 c.3.3 mode 1 .................................................................................................................. ....... c - 40 c.3.3.1 mode 1 baud rate ......................................................................................... c - 41 c.3.3.2 mode 1 transmit ............................................................................................ c - 43 c.3.4 mode 1 receive .......................................................................................................... . c - 43 c.3.5 mode 2 .................................................................................................................. ....... c - 45 c.3.5.1 mode 2 transmit ............................................................................................ c - 45 c.3.5.2 mode 2 receive ............................................................................................. c - 45 c.3.6 mode 3 .................................................................................................................. ....... c - 46 c.4 interrupts ................................................................................................................ .................. c - 48 c.5 interrupt-control sfrs .................................................................................................... ......... c - 48 c.5.1 803x/805x compatibility ............................................................................................... c - 52
viii table of contents (table of contents) c.6 interrupt processing ...................................................................................................... .......... c - 53 c.6.1 interrupt masking ....................................................................................................... .. c - 53 c.6.1.1 interrupt priorities .......................................................................................... c - 54 c.6.2 interrupt sampling ...................................................................................................... .. c - 55 c.6.3 interrupt latency ....................................................................................................... ... c - 55 appendix d register summary ............................................................................................................. ............ d - 59
ix list of figures figure 1-1. an2131s (44 pin) simplified block diagram ....................................................................1-2 figure 1-2. an2131q (80 pin) simplified block diagram ...................................................................1-3 figure 1-3. usb packets ....................................................................................................... .............1-4 figure 1-4. two bulk transfers, in and out .................................................................................... .1-6 figure 1-5. an interrupt transfer ............................................................................................. ...........1-7 figure 1-6. an isochronous transfer ........................................................................................... .......1-7 figure 1-7. a control transfer ................................................................................................ ............1-8 figure 1-8. what the sie does ................................................................................................. ..........1-9 figure 1-9. 80-pin pqfp package (an2131q) ................................................................................1-16 figure 1-10. 44-pin pqfp package with port b (an2131s) ..............................................................1-17 figure 1-11. 44-pin package with data bus (an2135, and an2136) .................................................1-18 figure 2-1. 8051 registers .................................................................................................... .............2-3 figure 3-1. ez-usb 8-kb memory map - addresses are in hexadecimal .........................................3-1 figure 3-2. ez-usb 4-kb memory map - addresses are in hexadecimal .........................................3-2 figure 3-3. unused bulk endpoint buffers (shaded) used as data memory .....................................3-3 figure 3-4. ez-usb memory map with ea=0 .....................................................................................3- 4 figure 3-5. ez-usb memory map with ea=1 .....................................................................................3- 6 figure 4-1. ez-usb input/output pin ........................................................................................... ......4-2 figure 4-2. alternate function is an output ................................................................................... .4-4 figure 4-3. alternate function is an input .................................................................................... ....4-4 figure 4-4. registers associated with ports a, b, and c ...............................................................4-5 figure 4-5. general i2c transfer .............................................................................................. .........4-6 figure 4-6. addressing an i2c peripheral ...................................................................................... ....4-7 figure 4-7. fc registers ...................................................................................................... ..............4-8 figure 5-1. usb control and status register ................................................................................... 5-10 figure 5-2. disconnect pin logic .............................................................................................. ........5-11 figure 5-3. typical disconnect circuit (discoe=1) .........................................................................5-11 figure 6-1. two bulk transfers, in and out ...................................................................................6 -1 figure 6-2. registers associated with bulk endpoints .......................................................................6-3 figure 6-3. anatomy of a bulk in transfer ..................................................................................... ....6-4 figure 6-4. anatomy of a bulk out transfer .................................................................................... .6-7 figure 6-5. bulk endpoint toggle control ...................................................................................... ..6-11 figure 6-6. example code for a simple (polled) bulk transfer .....................................................6-12 figure 6-7. interrupt jump table .............................................................................................. ........6-16 figure 6-8. int2 interrupt vector ............................................................................................. .........6-17 figure 6-9. interrupt service routine (isr) for endpoint 2-out ......................................................6-17 figure 6-10. background program transfers endpoint 2-out data to endpoint 2-in ......................6-18
x list of figures (list of figures) figure 6-11. initialization routine ........................................................................................... ............6-19 figure 6-12. autopointer registers ............................................................................................ ........6-20 figure 6-13. use of the autopointer ........................................................................................... ........6-21 figure 6-14. 8051 code to transfer external data to a bulk in buffer ..............................................6-22 figure 7-1. a usb control transfer (this one has a data stage) ....................................................7-2 figure 7-2. the two interrupts associated with ep0 control transfers ......................................7-3 figure 7-3. registers associated with ep0 control transfers ...........................................................7-4 figure 7-4. data flow for a get_status request ...............................................................................7 -7 figure 7-5. using the setup data pointer (sudptr) for get_descriptor requests ........................7-13 figure 8-1. ez-usb isochronous endpoints 8-15 ..............................................................................8-1 figure 8-2. isochronous in endpoint registers ................................................................................. 8-2 figure 8-3. isochronous out registers ......................................................................................... ....8-4 figure 8-4. fifo start address format ......................................................................................... .....8-5 figure 8-5. assembler translates fifo sizes to addresses .............................................................8-7 figure 8-6. 8051 code to transfer data to an isochronous fifo (in8data) ...................................8-8 figure 8-7. 8051 movx instructions ............................................................................................ ......8-9 figure 8-8. fast transfer, ez-usb to outside memory ...................................................................8-10 figure 8-9. fast transfer, outside memory to ez-usb ...................................................................8-10 figure 8-10. the fastxfr register controls frd# and fwr# strobes .........................................8-11 figure 8-11. fast write timing ................................................................................................ ...........8-12 figure 8-12. fast read timing ................................................................................................. ..........8-13 figure 8-13. 8051 code to transfer 640 bytes of external data to an isochronous in fifo ............8-14 figure 8-14. isoctl register .................................................................................................. ..........8-15 figure 8-15. zbcout register .................................................................................................. ........8-16 figure 9-1. ez-usb wakeup interrupt ........................................................................................... ....9-3 figure 9-2. usb interrupts .................................................................................................... .............9-4 figure 9-3. the order of clearing interrupt requests is important ....................................................9-6 figure 9-4. ez-usb interrupt registers ........................................................................................ .....9-7 figure 9-5. sutok and sudav interrupts ........................................................................................ 9-8 figure 9-6. a start of frame (sof) packet ..................................................................................... ..9-8 figure 9-7. the autovector mechanism in action ............................................................................9-11 figure 9-8. i 2 c interrupt enable bits and registers .........................................................................9-12 figure 9-9. i 2 c control and status register .....................................................................................9-13 figure 9-10. i 2 c data ........................................................................................................................ .9-13 figure 10-1. ez-usb resets .................................................................................................... ..........10-1 figure 11-1. suspend-resume control ........................................................................................... ...11-1 figure 11-2. ez-usb suspend sequence .........................................................................................1 1-2 figure 11-3. ez-usb resume sequence ..........................................................................................1 1-3 figure 11-4. usb control and status register .................................................................................. 11-4 figure 12-1. register description format ...................................................................................... ....12-2 figure 12-2. bulk data buffers ................................................................................................ ...........12-3
list of figures xi (list of figures) figure 12-3. isochronous data fifos .......................................................................................... .....12-4 figure 12-4. isochronous byte counts ......................................................................................... .....12-5 figure 12-5. cpu control and status register .................................................................................. 12-6 figure 12-6. io port configuration registers .................................................................................. ...12-7 figure 12-7. output port configuration registers .............................................................................. 12-9 figure 12-8. pinsn registers .................................................................................................. .........12-10 figure 12-9. output enable registers .......................................................................................... ....12-11 figure 12-10. isochronous out endpoint error register ..................................................................12-11 figure 12-11. isochronous control register .................................................................................... ...12-12 figure 12-12. zero byte count register ........................................................................................ .....12-12 figure 12-13. i 2 c transfer registers .................................................................................................12-13 figure 12-14. interrupt vector register ....................................................................................... .......12-15 figure 12-15. in/out interrupt request (irq) registers ..................................................................12-15 figure 12-16. usb interrupt request (irq) registers .......................................................................12-1 6 figure 12-17. in/out interrupt enable registers ..............................................................................1 2-17 figure 12-18. usb interrupt enable register ................................................................................... ..12-18 figure 12-19. breakpoint and autovector register ............................................................................12 -19 figure 12-20. in bulk nak interrupt request register ......................................................................12-1 9 figure 12-21. in bulk nak interrupt enable register ........................................................................12- 20 figure 12-22. in/out interrupt enable registers ..............................................................................1 2-20 figure 12-23. port configuration registers .................................................................................... ....12-21 figure 12-24. in control and status registers ................................................................................. ..12-24 figure 12-25. in byte count registers ......................................................................................... ......12-25 figure 12-26. out control and status registers ...............................................................................1 2-26 figure 12-27. out byte count registers ........................................................................................ ...12-27 figure 12-28. setup data pointer high/low registers .......................................................................12-2 8 figure 12-29. usb control and status registers ...............................................................................1 2-29 figure 12-30. data toggle control register .................................................................................... ...12-30 figure 12-31. usb frame count high/low registers ........................................................................12-31 figure 12-32. function address register ....................................................................................... ....12-31 figure 12-33. usb endpoint pairing register ................................................................................... .12-32 figure 12-34. in/out valid bits register ...................................................................................... .....12-33 figure 12-35. isochronous in/out endpoint valid bits register .......................................................12-33 figure 12-36. fast transfer control register .................................................................................. ...12-34 figure 12-37. auto pointer registers .......................................................................................... .......12-35 figure 12-38. setup data buffer ............................................................................................... .......12-36 figure 12-39. setup data buffer ............................................................................................... .......12-37 figure 13-1. external memory timing ........................................................................................... .....13-4 figure 13-2. program memory read timing ......................................................................................1 3-4 figure 13-3. data memory read timing .......................................................................................... ..13-5 figure 13-4. data memory write timing ......................................................................................... ...13-5
xii list of figures (list of figures) figure 13-5. fast transfer mode block diagram ...............................................................................13 -6 figure 13-6. fast transfer read timing [mode 00] ...........................................................................13- 7 figure 13-7. fast transfer write timing [mode 00] ............................................................................1 3-7 figure 13-8. fast transfer read timing [mode 01] ...........................................................................13- 8 figure 13-9. fast transfer write timing [mode 01] ..........................................................................13- 8 figure 13-10. fast transfer read timing [mode 10] ...........................................................................13 -9 figure 13-11. fast transfer write timing [mode 10] ............................................................................ 13-9 figure 13-12. fast transfer read timing [mode 11] .........................................................................13-1 0 figure 13-13. fast transfer write timing [mode 11] ..........................................................................13 -10 figure 14-1. 44-pin pqfp package (top view) ................................................................................14- 1 figure 14-2. 44-pin pqfp package (side view) ...............................................................................14- 1 figure 14-3. 44-pin pqfp package (detail view) .............................................................................14- 2 figure 14-4. 80-pin pqfp package (top view) ................................................................................14- 3 figure 14-5. 80-pin pqfp package (side view) ...............................................................................14- 3 figure 14-6. 80-pin pqfp package (detail view) .............................................................................14- 4 figure 14-7. 48-pin tqfp package (side view) ................................................................................14 -5 figure 14-8. 48-pin tqfp package (top view) .................................................................................14 -5 figure 14-9. 48-pin tqfp package (detail view) ..............................................................................14 -6 figure a-1. ez-usb cpu features ............................................................................................... .. a - 1 figure a-2. ez-usb to standard 8051 timing comparison ............................................................ a - 3 figure a-3. ez-usb internal data ram .......................................................................................... a - 6 figure b-1. internal data ram organization ................................................................................. b - 13 figure c-1. timer 0/1 - modes 0 and 1 ......................................................................................... .c - 25 figure c-2. timer 0/1 - mode 2 ................................................................................................ ...... c - 28 figure c-3. timer 0 - mode 3 .................................................................................................. ....... c - 29 figure c-4. timer 2 - timer/counter with capture ......................................................................... c - 3 2 figure c-5. timer 2 - timer/counter with auto reload .................................................................. c - 33 figure c-6. timer 2 - baud rate generator mode ........................................................................ c - 34 figure c-7. serial port mode 0 receive timing - low speed operation ....................................... c - 39 figure c-8. serial port mode 0 receive timing - high speed operation ...................................... c - 39 figure c-9. serial port mode 0 transmit timing - low speed operation ...................................... c - 40 figure c-10. serial port mode 0 transmit timing - high speed operation ..................................... c - 40 figure c-11. serial port 0 mode 1 transmit timing ......................................................................... c - 44 figure c-12. serial port 0 mode 1 receive timing ......................................................................... c - 4 4 figure c-13. serial port 0 mode 2 transmit timing ......................................................................... c - 46 figure c-14. serial port 0 mode 2 receive timing ......................................................................... c - 4 6 figure c-15. serial port 0 mode 3 transmit timing ......................................................................... c - 47 figure c-16. serial port 0 mode 3 receive timing ......................................................................... c - 4 7
xiii list of tables table 1-1. usb pids . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4 table 1-2. ez-usb series 2100 family . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 -15 table 1-3. ez-usb series 2100 pinouts by pin function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-19 table 2-1. ez-usb interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5 table 2-2. added registers and bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6 table 4-1. io pin functions for portxcfg=0 and portxcfg=1 . . . . . . . . . . . . . . . . . . . . . . . . 4-2 table 4-2. strap boot eeprom address lines to these values . . . . . . . . . . . . . . . . . . . . . . . . . 4-12 table 4-3. results of power-on i2c test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 -12 table 5-1. ez-usb default endpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2 table 5-2. how the ez-usb core handles ep0 requests when renum=0 . . . . . . . . . . . . . . . . . 5-3 table 5-3. firmware download . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-5 table 5-4. firmware upload . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-5 table 5-5. ez-usb core action at power-up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-6 table 5-6. ez-usb device characteristics, no serial eeprom . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-7 table 5-7. eeprom data format for ?b0? load . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-8 table 5-8. eeprom data format for ?b2? load . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-9 table 5-9. usb default device descriptor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 -12 table 5-10. usb default configuration descriptor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-1 3 table 5-11. usb default interface 0, alternate setting 0 descriptor . . . . . . . . . . . . . . . . . . . . . . . . 5-13 table 5-12. usb default interface 0, alternate setting 1 descriptor . . . . . . . . . . . . . . . . . . . . . . . . 5-14 table 5-13. usb default interface 0, alternate setting 1, interrupt endpoint descriptor . . . . . . . . . 5-14 table 5-14. usb default interface 0, alternate setting 1, bulk endpoint descriptors . . . . . . . . . . . 5-15 table 5-15. usb default interface 0, alternate setting 1, isochronous endpoint descriptors . . . . . 5-17 table 5-16. usb default interface 0, alternate setting 2 descriptor . . . . . . . . . . . . . . . . . . . . . . . . 5-18 table 5-17. usb default interface 0, alternate setting 1, interrupt endpoint descriptor . . . . . . . . . 5-18 table 5-18. usb default interface 0, alternate setting 2, bulk endpoint descriptors . . . . . . . . . . . 5-19 table 5-19. usb default interface 0, alternate setting 2, isochronous endpoint descriptors . . . . . 5-20 table 6-1. ez-usb bulk, control, and interrupt endpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-1 table 6-2. endpoint pairing bits (in the usb pair register) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-8 table 6-3. ez-usb endpoint 0-7 buffer addresses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-10 table 6-4. 8051 int2 interrupt vector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-14 table 6-5. byte inserted by ez-usb core at location 0x45 if aven=1 . . . . . . . . . . . . . . . . . . . . 6-14 table 7-1. the eight bytes in a usb setup packet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-5 table 7-2. how the 8051 handles usb device requests (renum=1) . . . . . . . . . . . . . . . . . . . . . . 7-6 table 7-3. get status-device (remote wakeup and self-powered bits) . . . . . . . . . . . . . . . . . . . . 7-8 table 7-4. get status-endpoint (stall bits) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-8
xiv list of tables (list of tables) table 7-5. get status-interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-9 table 7-6. set feature-device (set remote wakeup bit) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-10 table 7-7. set feature-endpoint (stall) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-10 table 7-8. clear feature-device (clear remote wakeup bit) . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-11 table 7-9. clear feature-endpoint (clear stall) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7- 12 table 7-10. get descriptor-device . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-14 table 7-11. get descriptor-configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-15 table 7-12. get descriptor-string . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-15 table 7-13. set descriptor-device . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-16 table 7-14. set descriptor-configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-16 table 7-15. set descriptor-string . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-16 table 7-16. set configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-18 table 7-17. get configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-18 table 7-18. set interface (actually, set alternate setting as for interface if) . . . . . . . . . . . . . . . . .7-19 table 7-19. get interface (actually, get alternate setting as for interface if) . . . . . . . . . . . . . . . . .7-20 table 7-20. sync frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-21 table 7-21. firmware download . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-22 table 7-22. firmware upload . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-22 table 8-1. isochronous endpoint fifo starting address registers . . . . . . . . . . . . . . . . . . . . . . . . .8-6 table 8-2. addresses for rd# and wr# vs. isodisab bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-15 table 9-1. ez-usb interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-1 table 9-2. 8051 jump instruction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-10 table 9-3. a typical usb jump table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-10 table 10-1. ez-usb states after power-on reset (por) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-2 table 10-2. ez-usb states after a usb bus reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-6 table 10-3. effects of an ez-usb disconnect and re-connect . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-7 table 10-4. effects of various ez-usb resets (?u? means ?unaffected?) . . . . . . . . . . . . . . . . . . . .10-8 table 12-1. bulk endpoint buffer memory addresses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-3 table 12-2. isochronous endpoint fifo register addresses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-4 table 12-3. isochronous endpoint byte count register addresses . . . . . . . . . . . . . . . . . . . . . . . . .12-5 table 12-4. io pin alternate functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-8 table 12-5. control and status register addresses for endpoints 0-7 . . . . . . . . . . . . . . . . . . . . . .12-23 table 12-6. isochronous fifo start address registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-37 table 13-1. dc characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13-1 table 13-2. general memory timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13-2 table 13-3. program memory read . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13-2 table 13-4. data memory read . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13-2 table 13-5. data memory write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13-3 table 13-6. fast data write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13-3 table 13-7. fast data read . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13-3
list of tables xv (list of tables) table a-1 ez-usb speed compared to standard 8051 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . a - 3 table a-2 comparison between ez-usb and other 803x/805x devices . . . . . . . . . . . . . . . . . . . a - 4 table a-3 differences between ez-usb and ds80c320 interrupts . . . . . . . . . . . . . . . . . . . . . . . a - 6 table a-4 ez-usb interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . a - 8 table a-5 ez-usb special function registers (sfr) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . a - 9 table a-6 special function registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . a - 10 table a-7 special function register reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . a - 11 table b-1 legend for instruction set table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . b - 15 table b-2 ez-usb instruction set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . b - 15 table b-3 data memory stretch values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . b - 2 0 table b-4 psw register - sfr 0xd0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . b - 21 table c-1 timer/counter implementation comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c - 24 table c-2 tmod register ? sfr 0x89. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c - 26 table c-3 tcon register ? srf 0x88 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c - 27 table c-4 ckcon (sfr 0x8e) timer rate control bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c - 29 table c-5 t2con register ? sfr 0xc8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c - 31 table c-6 timer 2 mode control summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c - 31 table c-7 serial port modes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c - 35 table c-8 serial interface implementation comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c - 35 table c-9 scon0 register ? sfr 98h. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c - 37 table c-10 eicon (sfr 0xd8) smod1 bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c - 37 table c-11 pcon (sfr 0x87) smod0 bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c - 37 table c-12 scon1 register ? sfr c0h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c - 38 table c-13 timer 1 reload values for common serial port mode 1 baud rates . . . . . . . . . . . . . c - 42 table c-14 timer 2 reload values for common serial port mode 1 baud rates . . . . . . . . . . . . . c - 43 table c-15 ez-usb interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c - 48 table c-16 ie register ? sfr 0xa8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c - 49 table c-17 ip register ? sfr 0xb8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c - 50 table c-18 exif register ? sfr 0x91 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c - 50 table c-19 eicon register ? sfr 0xd8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c - 51 table c-20 eie register ? sfr 0xe8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c - 51 table c-21 eip register ? sfr 0xf8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c - 52 table c-22 summary of interrupt compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c - 5 2 table c-23 interrupt flags, enables, priority control, and vectors . . . . . . . . . . . . . . . . . . . . . . . . c - 54
xvi list of tables (list of tables)
chapter 1. introducing ez-usb page 1-1 chapter 1 introducing ez-usb 1.1 introduction like a well designed automobile or appliance, a usb peripheral?s outward simplicity hides internal complexity. there?s a lot going on ?under the hood? of a usb device, which gives the user a new level of convenience. for example: ? a usb device can be plugged in anytime, even when the pc is turned on. ? when the pc detects that a usb device has been plugged in, it automatically interrogates the device to learn its capabilities and requirements. from this information, the pc auto- matically loads the device?s driver into the operating system. when the device is unplugged, the operating system automatically logs it off and unloads its driver. ? usb devices do not use dip switches, jumpers, or configuration programs. there is never an irq, dma, memory, or io conflict with a usb device. ? usb expansion hubs make the bus available to dozens of devices. ? usb is fast enough for printers, cd-quality audio, and scanners. usb is defined in the universal serial bus specification version 1.1 ( http://usb.org ), a 268-page document that describes all aspects of a usb device in elaborate detail. this ez-usb technical reference manual describes the ez-usb chip along with usb topics that should provide help in understanding the specification. the cypress semiconductor ez-usb is a compact integrated circuit that provides a highly inte- grated solution for a usb peripheral device. three key ez-usb features are: ? the ez-usb family provides a soft (ram-based) solution that allows unlimited configura- tion and upgrades. ? the ez-usb family delivers full usb throughput. designs that use ez-usb are not limited by number of endpoints, buffer sizes, or transfer speeds. ? the ez-usb family does much of the usb housekeeping in the ez-usb core, simplifying code and accelerating the usb learning curve.
ez-usb technical reference manual page 1-2 ez-usb technical reference manual v1.10 this chapter introduces some key usb concepts and terminology that should make reading the rest of this technical reference manual easier. 1.2 ez-usb block diagrams figure 1-1. an2131s (44 pin) simplified block diagram the cypress semiconductor ez-usb chip packs the intelligence required by a usb peripheral interface into a compact integrated circuit. as figure 1-1 illustrates, an integrated usb transceiver connects to the usb bus pins d+ and d-. a serial interface engine (sie) decodes and encodes the serial data and performs error correction, bit stuffing, and other signaling-level details required by usb, and ultimately transfers data bytes to and from the usb interface. the internal microprocessor is enhanced 8051 with fast execution time and added features. it uses internal ram for program and data storage, making the ez-usb family a soft solution. the usb host downloads 8051 program code and device personality into ram over the usb bus, and then the ez-usb chip re-connects as the custom device as defined by the loaded code. the ez-usb family uses an enhanced sie/usb interface (called the ?usb core?) which has the intelligence to function as a full usb device even before the 8051. the enhanced core simplifies 8051 code by implementing much of the usb protocol itself. ez-usb chips operate at 3.3v. this simplifies the design of bus-powered usb devices, since the 5v power available in the usb connector (which the usb specification allows to be as low as 4.4v) can drive a 3.3v regulator to deliver clean isolated power to the ez-usb chip. serial interface engine (sie) usb transceiver +5v gnd d+ d- usb connector bytes bytes io ports general purpose microprocessor usb interface program & data ram ez-usb
chapter 1. introducing ez-usb page 1-3 figure 1-2. an2131q (80 pin) simplified block diagram figure 1-2 illustrates the an2131q, an 80-pin version of the ez-usb family. in addition to the 24 io pins, it contains a 16-bit address bus and an 8-bit data bus for external memory expansion. a special fast transfer mode moves data directly between external logic and internal usb fifos. the fast transfer mode, along with abundant endpoint resources, allows the ez-usb family to sup- port transfer bandwidths beyond the maximum required by the universal serial bus specification version 1.1 . 1.3 the usb specification the universal serial bus specification version 1.1 is available on the internet at http://usb.org . published in january 1998, the specification is the work of a founding committee of seven industry heavyweights: compaq, dec, ibm, intel, microsoft, nec, and northern telecom. this impressive list of implementers secures usb as the low to medium speed pc connection method of the future. a glance at the usb specification makes it immediately apparent that usb is not nearly as simple as the customary serial or parallel port. the specification uses new terms like ?endpoint,? isochro- nous,? and ?enumeration,? and finds new uses for old terms like ?configuration,? ?interface,? and ?interrupt.? woven into the usb fabric is a software abstraction model that deals with things such as ?pipes.? the specification also contains detail about the connector types and wire colors. 1.4 tokens and pids in this manual, you will read statements like, ?when the host sends an in token...? or ?the device responds with an ack.? what do these terms mean? a usb transaction consists of data packets serial interface engine (sie) usb transceiver +5v gnd d+ d- usb connector bytes bytes io ports address bus data bus external memory, fifos, etc. general purpose microprocessor usb interface program & data ram ez-usb
ez-usb technical reference manual page 1-4 ez-usb technical reference manual v1.10 identified by special codes called packet ids or pids. a pid signifies what kind of packet is being transmitted. there are four pid types, as shown in table 1-1. figure 1-3. usb packets figure 1-3 illustrates a usb transfer. packet 1 is an out token, indicated by the out pid. the out token signifies that data from the host is about to be transmitted over the bus. packet 2 con- tains data, as indicated by the data1 pid. packet 3 is a handshake packet, sent by the device using the ack (acknowledge) pid to signify to the host that the device received the data error- free. continuing with figure 1-3, a second transaction begins with another out token 4 , followed by more data 5 , this time using the data0 pid. finally, the device again indicates success by trans- mitting the ack pid in a handshake packet 6 . why two data pids, data0 and data1? it?s because the usb architects took error correction very seriously. as mentioned previously, the ack handshake is a signal to the host that the peripheral received data without error (the crc portion of the packet is used to detect errors). but what if a handshake packet itself is garbled in transmission? to detect this, each side, host and device maintains a data toggle bit, which is toggled between data packet transfers. the state of this internal toggle bit is compared with the pid that arrives with the data, either data0 or data1. when sending data, the host or device sends alternating data0-data1 pids. by comparing the data pid with the state of the internal toggle bit, the host or device can detect a corrupted hand- shake packet. setup tokens are unique to control transfers. they preface eight bytes of data from which the peripheral decodes host device requests. table 1-1. usb pids pid type pid name token in, out, sof, setup data data0, data1 handshake ack, nak, stall special pre o u t a d d r e n d p c r c 5 token packet d a t a 1 payload data c r c 1 6 data packet a c k o u t a d d r e n d p c r c 5 token packet d a t a 0 payload data c r c 1 6 data packet a c k h/s pkt h/s pkt 1 2 3 4 5 6
chapter 1. introducing ez-usb page 1-5 sof tokens occur once per millisecond, denoting a usb frame . there are three handshake pids: ack, nak, and stall. ? ack means ?success;? the data was received error-free. ? nak means ?busy, try again.? it?s tempting to assume that nak means ?error,? but it doesn?t. a usb device indicates an error by not responding . ? stall means that something unforeseen went wrong (probably as a result of miscommu- nication or lack of cooperation between the software and firmware writers). a device sends the stall handshake to indicate that it doesn?t understand a device request, that something went wrong on the peripheral end, or that the host tried to access a resource that isn?t there. it?s like ?halt,? but better, because usb provides a way to recover from a stall. a pre (preamble) pid precedes a low-speed (1.5 mbps) usb transmission. the ez-usb family supports high-speed (12 mbps) usb transfers only, so it ignores pre packets and the subsequent low-speed transfer. 1.5 host is master this is a fundamental usb concept. there is exactly one master in a usb system: the host com- puter. usb devices respond to host requests. usb devices cannot send information between themselves, as they could if usb were a peer-to-peer topology. actually, there is one case where a usb device can initiate signaling without prompting from the host. after being put into a low-power suspend mode by the host, a device can signal a remote wakeup. but that?s the only way to ?yank the host?s chain.? everything else happens because the host makes device requests and the device responds to them. there?s an excellent reason for this host-centric model. the usb architects were keenly mindful of cost, and the best way to make low-cost peripherals is to put most of the smarts into the host side, the pc. if usb had been defined as peer-to-peer, every usb device would have required more intelligence, raising cost. here are two important consequences of the ?host is master? concept: 1.5.1 receiving data from the host to send data to a usb peripheral, the host issues an out token followed by the data. if the peripheral has space for the data, and accepts it without error, it returns an ack to the host. if it is busy, it instead sends a nak. if it finds an error, it sends nothing back. for the latter two cases, the host re-sends the data at a later time.
ez-usb technical reference manual page 1-6 ez-usb technical reference manual v1.10 1.5.2 sending data to the host a usb device never spontaneously sends data to the host. nevertheless, in the ez-usb chip, there?s nothing to stop the 8051 from loading data for the host into an endpoint buffer (section 1.13, "ez-usb endpoints") and arming it for transfer. but the data will sit in the buffer until the host sends an in token to that particular endpoint . if the host never sends the in token, the data sits there indefinitely. 1.6 usb direction once you accept that the host is the bus master, it?s easy to remember usb direction: out means from the host to the device, and in means from the device to the host. ez-usb nomenclature uses this naming convention. for example, an endpoint that sends data to the host is an in end- point. this can be confusing at first, because the 8051 sends data by loading an in endpoint buffer, but keeping in mind that an 8051 out is in to the host, it makes sense. 1.7 frame the usb host provides a time base to all usb devices by transmitting a sof (start of frame) packet every millisecond. the sof packet includes an incrementing, 11-bit frame count. the 8051 can read this frame count from two ez-usb registers. sof-time has significance for isoch- ronous endpoints; it?s the time that the ping-ponging buffers switch places. the ez-usb core pro- vides the 8051 with an sof interrupt request for servicing isochronous endpoint data. 1.8 ez-usb transfer types usb defines four transfer types. these match the requirements of different data types delivered over the bus. (section 1.13, "ez-usb endpoints" explains how the ez-usb family supports the four transfer types.) 1.8.1 bulk transfers figure 1-4. two bulk transfers, in and out i n a d d r e n d p c r c 5 token packet d a t a 1 payload data c r c 1 6 data packet a c k o u t a d d r e n d p c r c 5 token packet d a t a 0 payload data c r c 1 6 data packet a c k h/s pkt h/s pkt
chapter 1. introducing ez-usb page 1-7 bulk data is bursty , traveling in packets of 8, 16, 32, or 64 bytes. bulk data has guaranteed accu- racy, due to an automatic re-try mechanism for erroneous data. the host schedules bulk packets when there is available bus time. bulk transfers are typically used for printer, scanner, or modem data. bulk data has built-in flow control provided by handshake packets. 1.8.2 interrupt transfers figure 1-5. an interrupt transfer interrupt data is like bulk data, but exists only for in endpoints in the ?universal serial bus specifi- cation version 1.1.? interrupt data can have packet sizes of 1-64 bytes. interrupt endpoints have an associated polling interval that ensures that they will be pinged (will receive an in token) by the host on a regular basis. 1.8.3 isochronous transfers figure 1-6. an isochronous transfer isochronous data is time-critical and used for streaming data like audio and video. time of delivery is the most important requirement for isochronous data. in every usb frame, a certain amount of usb bandwidth is allocated to isochronous transfers. to lighten the overhead, isochronous trans- fers have no handshake (ack/nak/stall), and no retries. error detection is limited to a 16-bit crc. isochronous transfers do not use the data toggle mechanism; isochronous data uses only the data0 pid. i n a d d r e n d p c r c 5 token packet d a t a 1 payload data c r c 1 6 data packet a c k h/s pkt i n a d d r e n d p c r c 5 token packet d a t a 0 payload data c r c 1 6 data packet
ez-usb technical reference manual page 1-8 ez-usb technical reference manual v1.10 1.8.4 control transfers figure 1-7. a control transfer control transfers are used to configure and send commands to a device. being mission critical , they employ the most extensive error checking usb offers. control transfers are delivered on a best effort basis by the host ( best effort is defined by a six-step process in the universal serial bus specification version 1.1, ?section 5.5.4? ). the host reserves a part of each usb frame time for control transfers. control transfers consist of two or three stages. the setup stage contains eight bytes of usb control data. an optional data stage contains more data, if required. the status (or hand- shake ) stage allows the device to indicate successful completion of a control operation. 1.9 enumeration your computer is on. you plug in a usb device, and the windows ? cursor switches to an hour- glass, and then back to a cursor. and magically, your device is connected and its windows ? driver is loaded! anyone who has installed a sound card into a pc and had to configure countless jumpers, drivers, and io/interrupt/dma settings knows that a usb connection can be like a mira- cle. we?ve all heard about plug and play, but usb delivers the real thing. how does all this happen automatically? inside every usb device is a table of ?descriptors? that are the sum total of the device?s requirements and capabilities. when you plug into usb, the host goes through a ?sign-on? sequence: 1. the host sends a ?get_descriptor/device? request to address zero (devices must respond to address zero when first attached). i n a d d r e n d p c r c 5 token packet d a t a 0 8 bytes setup data c r c 1 6 data packet a c k h/s pkt s e t u p a d d r e n d p c r c 5 token packet d a t a 1 payload data c r c 1 6 data packet a c k h/s pkt d a t a 1 o u t a d d r e n d p c r c 5 token packet c r c 1 6 data pkt a c k h/s pkt setup stage data stage (optional) status stage
chapter 1. introducing ez-usb page 1-9 2. the device dutifully responds to this request by sending id data back to the host telling what it is. 3. the host sends the device a ?set_address? request, which gives it a unique address to distin- guish it from the other devices connected to the bus. 4. the host sends more ?get_descriptor? requests, asking more device information. from this, it learns everything else about the device, like how many endpoints the device has, its power requirements, what bus bandwidth it requires, and what driver to load. this sign-on process is called enumeration . 1.10 the usb core figure 1-8. what the sie does every usb device has a serial interface engine (sie). the sie connects to the usb data lines d+ and d-, and delivers bytes to and from the usb device. figure 1-8 illustrates a usb bulk transfer, with time moving from left to right. the sie decodes the packet pids, performs error checking on the data using the transmitted crc bits, and delivers payload data to the usb device. if the sie encounters an error in the data, it automatically indicates no response instead of supplying a hand- shake pid. this instructs the host to re-transmit the data at a later time. bulk transfers such as the one illustrated in figure 1-8 are asynchronous , meaning that they include a flow control mechanism using ack and nak handshake pids. the sie indicates busy serial interface engine (sie) d+ d- usb tranceiver o u t a d d r e n d p c r c 5 token packet d a t a 1 payload data c r c 1 6 data packet a c k o u t a d d r e n d p c r c 5 token packet d a t a 0 payload data c r c 1 6 data packet a c k h/s pkt payload data payload data a c k h/s pkt
ez-usb technical reference manual page 1-10 ez-usb technical reference manual v1.10 to the host by sending a nak handshake packet. when the peripheral device has successfully transferred the data, it commands the sie to send an ack handshake packet, indicating success. to send data to the host, the sie accepts bytes and control signals from the usb device, formats it for usb transfer, and sends it over the two-wire usb. because the usb uses a self-clocking data format (nrzi), the sie also inserts bits at appropriate places in the bit stream to guarantee a certain number of transitions in the serial data. this is called ?bit stuffing,? and is transparently handled by the sie. one of the most important features of the ez-usb family is that it is soft . instead of requiring rom or other fixed memory, it contains internal program/data ram that is downloaded over the usb itself to give the device its unique personality. this make modifications, specification revi- sions, and updates a snap. the ez-usb family can connect as a usb device and download code into internal ram, all while its internal 8051 is held in reset. this is done by an enhanced sie, which does all of the work shown in figure 1-8, and more. it contains additional logic to perform a full enumeration, using an internal table of descriptors. it also responds to a vendor specific ?firmware download? device request to load its internal ram. an added bonus is that the added sie functionality is also made available to the 8051. this saves 8051 code and processing time. throughout this manual, the sie and its enhancements are referred to as the ?usb core.? 1.11 ez-usb microprocessor the ez-usb microprocessor is an enhanced 8051 core. use of an 8051 compatible processor makes extensive software support tools immediately available to the ez-usb designer. this enhanced 8051 core, described in chapter 2, "ez-usb cpu" and appendices a-c, has the follow- ing features: ? 4-clock cycle, as compared to the 12-clock cycle of a standard 8051, giving a 3x speed improvement. ? dual data pointers for faster memory-to-memory transfers. ? two uarts. ? three counter-timers. ? an expanded interrupt system. ? 24-mhz clock. ? 256 bytes of internal register ram. ? standard 8051 instruction set?if you know the 8051, you know ez-usb
chapter 1. introducing ez-usb page 1-11 the enhanced 8051 core uses on-chip ram as program and data memory, giving ez-usb its soft feature. chapter 3, "ez-usb memory" describes the various memory options. the 8051 communicates with the sie using a set of registers, which occupy the top of the on-chip ram address space. these registers are grouped and described by function in individual chapters of this reference manual, and summarized in register order in chapter 12, "ez-usb registers." the ez-usb 8051 has two duties. first, it participates in the protocol defined in the universal serial bus specification version 1.1, ?chapter 9, usb device framework.? thanks to ez-usb enhancements to the sie and usb interface, the 8051 firmware associated with usb overhead is simplified, leaving code space and bandwidth available for the 8051?s primary duty, to help imple- ment your device. on the device side, abundant input/output resources are available, including io ports, uarts, and an i 2 c bus master controller. these resources are described in chapter 4, "ez- usb input/output." 1.12 renumeration? because it is soft , the ez-usb chip can take on the identities of multiple distinct usb devices. the first device downloads your 8051 firmware and usb descriptor tables over the usb cable when the peripheral device is plugged in. once downloaded, another device comes on as a totally differ- ent usb peripheral as defined by the downloaded information. this two-step process, called renumeration? , happens instantly when the device is plugged in, with no hint that the initial load step has occurred. chapter 5, "ez-usb enumeration and renumeration?" describes this feature in detail, along with other ez-usb boot (startup) modes. 1.13 ez-usb endpoints the universal serial bus specification version 1.1 defines an endpoint as a source or sink of data. since usb is a serial bus, a device endpoint is actually a fifo which sequentially empties/fills with usb bytes. the host selects a device endpoint by sending a 4-bit address and one direction bit. therefore, usb can uniquely address 32 endpoints, in0 through in15 and out0 through out15. from the ez-usb point of view, an endpoint is a buffer full of bytes received or to be transmitted over the bus. the 8051 reads endpoint data from an out buffer, and writes endpoint data for transmission over usb to an in buffer. four usb endpoint types are defined as: bulk, control, interrupt, and isochronous.
ez-usb technical reference manual page 1-12 ez-usb technical reference manual v1.10 1.13.1 ez-usb bulk endpoints bulk endpoints are unidirectional?one endpoint address per direction. therefore endpoint 2-in is addressed differently than endpoint 2-out. bulk endpoints use maximum packet sizes (and therefore buffer sizes) of 8, 16, 32, or 64 bytes. ez-usb provides fourteen bulk endpoints, divided into seven in endpoints (endpoint 1-in through 7-in), and seven out endpoints (endpoint 1-out through 7-out). each of the fourteen endpoints has a 64-byte buffer. bulk data is available to the 8051 in ram form, or as fifo data using a special ez-usb auto- pointer (chapter 6, "ez-usb bulk transfers"). 1.13.2 ez-usb control endpoint zero control endpoints transfer mission-critical control information to and from the usb device. the universal serial bus specification version 1.1 requires every usb device to have a default con- trol endpoint, endpoint zero. device enumeration, the process that the host initiates when the device is first plugged in, is conducted over endpoint zero. the host sends all usb requests over endpoint zero. control endpoints are bi-directional; if you have an endpoint 0 in control endpoint, you auto- matically have an endpoint 0 out endpoint. control endpoints alone accept setup pids. a control transfer consists of a two or three stage sequence: ?setup ? data (if needed) ? handshake eight bytes of data in the setup portion of the control transfer have special usb significance, as defined in the universal serial bus specification version 1.1, ?chapter 9.? a usb device must respond properly to the requests described in this chapter to pass usb compliance testing (usu- ally referred to as the usb ?chapter nine test?). endpoint zero is the only control endpoint in the ez-usb chip. the 8051 responds to device requests issued by the host over endpoint zero. the ez-usb core is significantly enhanced to simplify the 8051 code required to service these requests. chapter 7, "ez-usb endpoint zero" provides a detailed roadmap for writing usb chapter 9 compliant 8051 code. 1.13.3 ez-usb interrupt endpoints interrupt endpoints are almost identical to bulk endpoints. fourteen ez-usb endpoints (ep1-ep7, in, and out) may be used as interrupt endpoints. interrupt endpoints have maximum packet sizes up to 64, and contain a ?polling interval? byte in their descriptor to tell the host how often to
chapter 1. introducing ez-usb page 1-13 service them. the 8051 transfers data over interrupt endpoints in exactly the same way as for bulk endpoints. interrupt endpoints are described in chapter 6, "ez-usb bulk transfers." 1.13.4 ez-usb isochronous endpoints isochronous endpoints deliver high bandwidth, time critical data over usb. isochronous endpoints are used to stream data to devices such as audio dacs, and from devices such as cameras and scanners. time of delivery is the most critical requirement, and isochronous endpoints are tailored to this requirement. once a device has been granted an isochronous bandwidth slot by the host, it is guaranteed to be able to send or receive its data every frame. ez-usb contains 16 isochronous endpoints, numbered 8-15 (8in-15in, and 8out-15out). 1,024 bytes of fifo memory are available to the 16 endpoints, and may be fifo memory to pro- vide double-buffering. using double buffering, the 8051 reads out data from isochronous end- point fifos containing data from the previous frame while the host writes current frame data into the other buffer. similarly, the 8051 loads in data into isochronous endpoint fifos that will be transmitted over usb during the next frame while the host reads current frame data from the other buffer. at every sof the usb fifos and 8051 fifos switch, or ping-pong . isochronous transfers are described in chapter 8, "ez-usb isochronous transfers." 1.14 fast transfer modes the following versions of the ez-usb have a fast transfer mode: an2135sc, an2136sc, and an2131qc, that is, those versions that have a data bus (see table 1-2). the fast transfer mode minimizes the transfer time from ez-usb core also supplies external fifo read and write strobes to synchronize the transfers. using the fast transfer mode, the 8051 transfers a byte of data between an internal fifo and the external bus using a single 8051 movx instruction, which takes two cycles or 333 ns. both isoch- ronous and bulk endpoints can use this fast transfer mode. 1.15 interrupts the ez-usb enhanced 8051 adds seven interrupt sources to the standard 8051 interrupt system. three of the added interrupts are used internally, and the others are available on device pins. int2 is used for all usb interrupts. int3 is used by the i 2 c interface. a third interrupt is used for remote wakeup indication. the ez-usb core automatically supplies jump vectors (autovectors) for its usb interrupts to save the 8051 from having to test bits to determine the source of the interrupt. each bulk/control/ interrupt endpoint has its own vector, so when an endpoint requires service, the proper inter- rupt service routine is automatically invoked. the 8051 services all isochronous endpoints in
ez-usb technical reference manual page 1-14 ez-usb technical reference manual v1.10 response to a sof (start of frame) interrupt request. chapter 9, "ez-usb interrupts" describes the ez-usb interrupt system. 1.16 reset and power management the ez-usb chip contains four resets: ? power-on-reset (por) ? usb bus reset ? 8051 reset ? usb disconnect/re-connect the functions of the various ez-usb resets are described in chapter 10, "ez-usb resets." a usb peripheral may be put into a low power state when the host signals a suspend operation. the universal serial bus specification version 1.1 states that a bus powered device cannot draw more than 500 u a of current from the vcc wire while in suspend. the ez-usb chip contains logic to turn off its internal oscillator and enter a sleep state. a special interrupt, triggered by a wakeup pin or wakeup signaling on the usb bus, starts the oscillator and interrupts the 8051 to resume operation. low power operation is described in chapter 11, "ez-usb power management."
chapter 1. introducing ez-usb page 1-15 1.17 ez-usb product family the ez-usb family is available in various pinouts to serve different system requirements and costs. table 1-2 shows the feature set for each member of the ez-usb series 2100 family. 1.18 pin descriptions figures 1-9 through 1-11 are pin descriptions by package type. table 1-3 describes the pins by pin function. table 1-2. ez-usb series 2100 family part number ram size key features package max uart (async) speed (kbaud) power saving option ibn/ stop iso sup- port end- points data bus or port b i/o rate bytes/s max prog i/os an2131q 8kb y 32 both 2m 24 q = 80 pqfp 115.2 n n a n 2 1 31s 8kb y 32 port b 6 00k 1 8 s = 4 4 p q fp 1 15 . 2 n n an2135s 8kb y 32 data bus 2m 8 s = 44 pqfp 115.2 n n an2136s 8kb n 16 data bus 2m 8 s = 44 pqfp 115.2 n n
ez-usb technical reference manual page 1-16 ez-usb technical reference manual v1.10 figure 1-9. 80-pin pqfp package (an2131q) 40 38 37 36 35 34 33 32 31 30 29 28 27 26 25 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 80 pqfp 14 x 20 mm sda gnd vcc bkpt d7 d6 d5 d4 gnd pb7/t2out pb6/int6 pb5/int5# pb4/int4 d3 d2 d1 d0 pb3/txd1 pb2/rxd1 pb1/t2ex pb0/t2 gnd vcc pc7/rd# pc0/rxd0 pc1/txd0 pc2/int0# pc3/int1# pc4/t0 pc6/wr# a8 a9 a15 a14 a13 a12 a11 a10 pc5/t1 reset scl wakeup# gnd usbd+ pa0/t0out pa1/t1out pa2/oe# pa3/cs# pa4/fwr# pa5/frd# pa6/rxd0out pa7/rxd1out nc usbd- psen# gnd 123456789 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 64 63 62 61 39 gnd a6 a7 gnd agnd xin xout avcc vcc gnd ea discon# vcc gnd clk24 gnd gnd a0 a1 a2 a3 a4 a5 gnd
chapter 1. introducing ez-usb page 1-17 figure 1-10. 44-pin pqfp package with port b (an2131s) gnd reset vcc pc0/rxd0 pc1/txd0 pc2/int0# pc3/int1# pc4/t0 pc6/w r# pc7/rd # pc5/t1 avcc xout xin agnd gnd vcc clk24 gnd gnd gnd gnd gnd pb1/t2ex pb2/rxd2 pb3/txd2 pb4/int4 pb5/int5# pb6/int6 pb0/t2 vcc pb7/t2out bkpt scl sda gnd vcc wakeup# discon# usbd+ pa4/fw r# pa5/frd# gnd usbd- 12 13 14 15 16 17 20 18 19 21 22 44 43 42 41 40 39 36 38 37 35 34 33 32 31 30 29 28 25 27 26 24 23 1 2 3 4 5 6 9 7 8 10 11 44 pqfp 10 x 10 mm
ez-usb technical reference manual page 1-18 ez-usb technical reference manual v1.10 figure 1-11. 44-pin package with data bus (an2135, and an2136) gnd reset vcc pc0/rxd0 pc1/txd0 pc2/int0 # pc3/int1 # pc4/t0 pc6/w r # pc7/rd# pc5/t1 avcc xout xin agnd gnd vcc clk24 gnd gnd gnd gnd scl sda gnd vcc wakeup# discon# usbd+ pa4/fw r# pa5/frd# gnd usbd- gnd d1 d2 d3 d4 d5 d6 d0 vcc d7 bkpt 12 13 14 15 16 17 20 18 19 21 22 44 43 42 41 40 39 36 38 37 35 34 33 32 31 30 29 28 25 27 26 24 23 1 2 3 4 5 6 9 7 8 10 11 44 pqfp 10 x 10 mm
chapter 1. introducing ez-usb page 1-19 table 1-3. ez-usb series 2100 pinouts by pin function 2131q 2121s 2122s 2131s 2125s 2126s 2135s 2136s 2122t 2126t name type default description 21 10 10 11 11 avcc power n/a analog vcc . this signal provides power to the analog section of the chip. 18 7 7 7 7 agnd power n/a analog ground . connect to ground with as short a path as possible. 1 43 43 47 47 discon# output hi disconnect . this pin is controlled by two bits, discoe and discon. when discoe=0, the pin floats. when discoe=1, it drives. when discoe=1, the driven logic level is the inverse of the discon bit. 77 41 41 45 45 usbd i/o/z z usb d- signal . connect to the usb d- signal through a 24-ohm resistor. 79 42 42 46 46 usbd i/o/z z usb d+ signal . connect to the usb d+ pin through a 24-ohm resistor. 7-12, 15, 16, 26-29, 34-37 n/a n/a n/a n/a a0-a5, a6, a7, a8-a11, a12-a15 output 0x0000 8051 address bus . this bus is driven at all times. when the 8051 is addressing internal ram it reflects the internal address. 48-51, 57-60 n/a 24-27, 28-31 n/a 26-29, 30-33 d0-d3, d4-d7 i/o/z z 8051 data bus . this bi-directional bus is high-impedance when inactive, input for bus reads, and output for bus writes. the data bus is also used to transfer data directly to and from internal ez-usb fifos under control of the frd# and fwr# strobes. d0-d7 are active only for external bus accesses, and are driven low in suspend. 80 n/a n/a n/a n/a psen# output h program store enable . this active-low sig- nal indicates a code fetch from external mem- ory. it is active for program memory fetches above 0x1b40 when the ea pin is lo, or above 0x0000 when the ea pin is hi. 61 32 32 35 35 bkpt output 0 breakpoint . this pin goes active (high) when the 8051 address bus matches the bpad- drh/l registers and breakpoints are enabled in the usbbav register (bpen=1). if the bppulse bit in the usbbav register is hi, this signal pulses high for eight 24-mhz clocks. if the bppulse bit is lo, the signal remains high until the 8051 clears the break bit (by writing 1 to it) in the usbbav register. 25 13 13 14 14 reset input n/a active high reset . resets the 8051 and the usb sie. this pin is normally tied to ground through a 10k-ohm resistor and to vcc through a 1 mf capacitor.
ez-usb technical reference manual page 1-20 ez-usb technical reference manual v1.10 24 n/a n/a n/a n/a ea input n/a external access . if this signal is active (high), the 8051 fetches code from external memory instead of the internal program ram. if ea=0, the 8051 fetches code from external memory starting at 0x1b40 (an2131). 19 8 8 9 9 xin input n/a crystal input . connect this signal to a 12- mhz series resonant, fundamental mode crys- tal and 22-33-pf capacitor to gnd. this pin may also be driven by a 12-mhz clock. 20 9 9 10 10 xout output n/a crystal output. connect this signal to a 12- mhz series resonant, fundamental mode crys- tal and 22-33-pf capacitor to gnd. if xin is driven by a 12-mhz clock, this pin should not be connected. 68 n/a n/a 34 34 pa0 or t0out i/o i (pa0) multiplexed pin whose function is selected by the t0out bit of the portacfg register. if t0out=0, the pin is the bi-directional i/o port bit pa0. if t0out=1, the pin is the active-high t0out signal from 8051 timer/counter0. t0out outputs a high level for one clk24 clock cycle when timer0 overflows. if timer0 is operated in mode 3 (two separate timer/ counters), t0out is active when the low byte timer/counter overflows. 69 n/a n/a n/a n/a pa1 or t1out i/o i (pa1) multiplexed pin whose function is selected by the t1out bit of the portacfg register. if t1out=0, the pin is the bi-directional i/o port bit pa1. if t1out=1, the pin is the active-high t1out signal from 8051 timer-counter1. t1out outputs a high level for one clk24 clock cycle when timer1 overflows. if timer1 is operated in mode 3 (two separate timer/ counters), t1out is active when the low byte timer/counter overflows. 70 n/a n/a n/a n/a pa2 or oe# i/o i (pa2) multiplexed pin whose function is selected by the oe bit of the portacfg register. if oe=0, the pin is the bi-directional i/o port pin pa2. if oe=1, the pin is an active-low output enable for external memory. if the oe# pin is used, it should be externally pulled up to vcc to ensure that the write strobe is inactive (high) at power-on. table 1-3. ez-usb series 2100 pinouts by pin function (continued) 2131q 2121s 2122s 2131s 2125s 2126s 2135s 2136s 2122t 2126t name type default description
chapter 1. introducing ez-usb page 1-21 71 n/a n/a n/a n/a pa3 or cs# i/o i (pa3) multiplexed pin whose function is selected by the cs bit of the portacfg register. if cs=0, the pin is the bi-directional i/o port pin pa3. if cs=1, the pin is an active-low chip select for external memory. if the cs# pin is used, it should be externally pulled up to vcc to ensure that the write strobe is inactive (high) at power-on. 73 39 39 n/a n/a pa4 or fwr# i/o i (pa4) multiplexed pin whose function is selected by the fwr (fast write) bit of the portafcg register. if fwr=0, the pin is the bi-directional i/o port pin pa4. if fwr=1, the pin is the write strobe for an external fifo. if the fwr# pin is used, it should be externally pulled up to vcc to ensure that the write strobe is inactive (high) at power-on. 74 40 40 n/a n/a pa5 or frd# i/o i (pa5) multiplexed pin whose function is selected by the frd (fast read) bit of the portafcg register. if frd=0, the pin is the bi-directional i/o port pin pa5. if frd=1, the pin is the read strobe for an external fifo. if the frd# pin is used, it should be externally pulled up to vcc to ensure that the write strobe is inactive (high) at power-on. 75 n/a n/a 44 44 pa6 or rxd0out i/o i (pa6) multiplexed pin whose function is selected by the rxd0out bit of the portafcg regis- ter. if rxd0out=0 (default), the pin is the bi- directional i/o port bit pa6. if rxd0out=1, the pin is the active-high rxd0out signal from 8051 uart0. if rxd0out is selected and uart0 is in mode 0, this pin provides the output data for uart0 only when it is in sync mode. other- wise, it is a 1. 76 n/a n/a 8 8 pa7 or rxd1out i/o i (pa7) multiplexed pin whose function is selected by the rxd1out bit of the portafcg regis- ter. if rxd1out=0 (default), the pin is the bi- directional i/o port bit pa7. if rxd1out=1, the pin is the active-high rxd1out signal from 8051 uart1. when rxd1out is selected and uart1 is in mode 0, this pin provides the output data for uart1 only when it is in sync mode. in modes 1, 2, and 3, this pin is a 1. table 1-3. ez-usb series 2100 pinouts by pin function (continued) 2131q 2121s 2122s 2131s 2125s 2126s 2135s 2136s 2122t 2126t name type default description
ez-usb technical reference manual page 1-22 ez-usb technical reference manual v1.10 44 24 n/a 26 n/a pb0 or t2 i/o i (pb0) multiplexed pin whose function is selected by the t2 bit of the portbfcg register. if t2=0, the pin is the bi-directional i/o port bit pb0. if t2=1, the pin is the active-high t2 signal from 8051 timer2, which provides the input to timer2 when c/t2=1. when c/t2=0, timer2 does not use this pin. 45 25 n/a 27 n/a pb1 or t2ex i/o i (pb1) multiplexed pin whose function is selected by the t2ex bit of the portbcfg register. if t2ex=0, the pin is the bi-directional i/o port bit pb1. if t2ex=1, the pin is the active-high t2ex signal from 8051 timer2. 46 26 n/a 28 n/a pb2 or rxd1 i/o i (p{b2) multiplexed pin whose function is selected by the rxd1 bit of the portbcfg register. if rxd1=0, the pin is the bi-directional i/o port bit pb2. if rxd1=1, the pin is the active-high rxd1 input signal for 8051 uart1, which provides data to the uart in all modes. 47 27 n/a 29 n/a pb3 or txd1 i/o i (pb3) multiplexed pin whose function is selected by the txd1 bit of the portbcfg register. if txd1=0, the pin is the bi-directional i/o port bit pb3. if txd1=1, the pin is the active-high txd1 output pin for 8051 uart1 which pro- vides the output clock in sync mode and the output data in async mode. 52 28 n/a 30 n/a pb4 or int4 i/o i (pb4) multiplexed pin whose function is selected by the int4 bit of the portbcfg register. if int4=0, the pin is the bi-directional i/o port bit pb4. if int4=1, the pin is the 8051 int4 inter- rupt request signal. the int4 pin is edge-sen- sitive, active high. 53 29 n/a 31 n/a pb5 or int5# i/o i (pb5) multiplexed pin whose function is selected by the int5 bit of the portbcfg register. if int5=0, the pin is the bi-directional i/o port bit pb5. if int5=1, the pin is the int5# interrupt register signal. the int5# pin is edge-sensi- tive, active low. 54 30 n/a 32 n/a pb6 or int6 i/o i (pb6) multiplexed pin whose function is selected by the int6 bit of the portbcfg register. if int6=0, the pin is the bi-directional i/o port bit pb6. if int6=1, the pin is the int6 interrupt request signal. the int6 pin is edge-sensi- tive, active high. table 1-3. ez-usb series 2100 pinouts by pin function (continued) 2131q 2121s 2122s 2131s 2125s 2126s 2135s 2136s 2122t 2126t name type default description
chapter 1. introducing ez-usb page 1-23 55 31 n/a 33 n/a pb7 or t2out i/o i (pb7) multiplexed pin whose function is selected by the t2out bit of the portbcfg register. if t2out=0, the pin is the bi-directional i/o port bit pb7. if t2out=1, the pin is the active-high t2out signal from 8051 timer2. t2out is active (high) for one clock cycle when timer/counter 2 overflows. 30 14 14 16 16 pc0 or rxd0 i/o i (pc0) multiplexed pin whose function is selected by the rxd0 bit of the portccfg register. if rxd0=0, the pin is the bi-directional i/o port bit pc0. if rxd0=1, the pin is the active-high rxd0 from 8051 uart0, which provides data to the uart in all modes. 31 15 15 17 17 pc1 or txd0 i/o i (pc1) multiplexed pin whose function is selected by the txd0 bit of the portccfg register. if txd0=0, the pin is the bi-directional i/o port bit pc1. if txd0=1, the pin is the active-high txd0 signal for 8051 uart0, which provides the output clock in sync mode, and the output data in async mode. 32 16 16 18 18 pc2 or int0# i/o i (pc2) multiplexed pin whose function is selected by the int0 bit of the portccfg register. if int0=0, the pin is the bi-directional i/o port bit pc2. if int0=1, the pin is the active-low 8051 int0 interrupt input signal, which is either edge triggered (it0=1) or level triggered (it0=0). 33 17 17 19 19 pc3 or int1# i/o i (pc3) multiplexed pin whose function is selected by the int1 bit of the portccfg register. if int1=0, the pin is the bi-directional i/o port bit pc3. if int1=1, the pin is the active-low 8051 int1 interrupt input signal, which is either edge triggered (it1=1) or level triggered (it1=0). 38 18 18 20 20 pc4 or t0 i/o i (pc4) multiplexed pin whose function is selected by the t0 bit of the portccfg register. if t0=0, the pin is the bi-directional i/o port bit pc4. if t0=1, the pin is the active-high t0 signal for 8051 timer0, which provides the input to timer0 when c/t0 is 1. when c/t0 is 0, timer0 does not use this bit. table 1-3. ez-usb series 2100 pinouts by pin function (continued) 2131q 2121s 2122s 2131s 2125s 2126s 2135s 2136s 2122t 2126t name type default description
ez-usb technical reference manual page 1-24 ez-usb technical reference manual v1.10 39 19 19 21 21 pc5 or t1 i/o i (pc5) multiplexed pin whose function is selected by the t1 bit of the portccfg register. if t1=0, the pin is the bi-directional i/o port bit pc5. if t1=1, the pin is the active-high t1 signal from 8051 timer1, which provides the input to timer1 when c/t1 is 1. when c/t0 is 0, timer1 does not use this bit. 40 20 20 22 22 pc6 or wr# i/o i (pc6) multiplexed pin whose function is selected by the wr bit of the portccfg register. if wr=0, the pin is the bi-directional i/o port bit pc6. if wr=1, the pin is the active-low write signal for external memory. if the wr# signal is used, it should be externally pulled up to vcc to ensure that the write strobe is inactive at power-on. 41 21 21 23 23 pc7 or rd# i/o i (pc7) multiplexed pin whose function is selected by the rd bit of the portccfg register. if rd#=0, the pin is the bi-directional i/o port bit pc7. if rd#=1, the pin is the active-low read signal for external memory. if the rd# signal is used, it should be externally pulled up to vcc to ensure that the read strobe is inactive at power-on. 4 2 2 2 2 clk24 output 24-mhz clock , phase locked to the 12-mhz input clock. it operates at 12 mhz in 12-mhz mode (48-pin package). output is disabled by setting the outclken bit = 0 in the cpucs register. 66 37 37 40 40 wakeup# input n/a usb wakeup . if the 8051 is in suspend, a high to low edge on this pin starts up the oscil- lator and interrupts the 8051 to allow it to exit the suspend mode. holding wakeup# low inhibits the ez-usb chip from entering the suspend state. 65 36 36 39 39 scl od z i 2 c clock . pull up to vcc with a 2.2k-ohm resistor, even if no i 2 c device is connected. 64 35 35 38 38 sda od z i 2 c data . connect to vcc with a 2.2k-ohm resistor even if no i 2 c device is connected. 2, 22, 42, 62 11, 22, 33, 44 11, 22, 33, 44 12, 24, 36, 48 12, 24, 36, 48 vcc n/a vcc . 3.3v power source. table 1-3. ez-usb series 2100 pinouts by pin function (continued) 2131q 2121s 2122s 2131s 2125s 2126s 2135s 2136s 2122t 2126t name type default description
chapter 1. introducing ez-usb page 1-25 3, 5, 6, 13, 14, 17, 23, 43, 56, 63, 72, 78 1, 3, 4, 5, 6, 12, 23, 34, 38 1, 3, 4, 5, 6, 12, 23, 34, 38 1, 3, 4, 5, 6, 13, 25, 37, 41 1, 3, 4, 5, 6, 13, 25, 37, 41 gnd n/a ground. note: on the 80-pin package, pins 5, 6, 13, 14, and 72 are test pins that must be grounded for normal operation. driving pin 72 high floats all functional pins for automated board test. the corresponding pins on the 44-pin pack- age are pins 3, 4, 5, 6, and 38. driving pin 38 high floats all functional pins for automated board test. the corresponding pins on the 48-pin pack- age are pins 3, 4, 5, 6, and 41. driving pin 41 high floats all functional pins for automated board testing. n/a n/a n/a 15 15 cpu12mhz n/a this input controls the speed of the 8051: - tied high - 12 mhz - tied low - 24 mhz 67 n/a n/a n/a n/a nc n/a this pin must be left unconnected. table 1-3. ez-usb series 2100 pinouts by pin function (continued) 2131q 2121s 2122s 2131s 2125s 2126s 2135s 2136s 2122t 2126t name type default description
ez-usb technical reference manual page 1-26 ez-usb technical reference manual v1.10
chapter 2. ez-usb cpu page 2-1 chapter 2 ez-usb cpu 2.1 introduction the ez-usb built-in microprocessor, an enhanced 8051 core, is fully described in appendices a- c. this chapter introduces the processor, its interface to the ez-usb core, and describes architec- tural differences from a standard 8051. 2.2 8051 enhancements the enhanced 8051 core uses the standard 8051 instruction set. instructions execute faster than with the standard 8051 due to two features: ? wasted bus cycles are eliminated. a bus cycle uses four clocks, as compared to 12 clocks with the standard 8051. ? the 8051 runs at 24 mhz. in addition to the speed improvement, the enhanced 8051 core also includes architectural enhancements: 1. a second data pointer. 2. a second uart. 3. a third, 16-bit timer (timer2). 4. a high-speed memory interface with a non-multiplexed 16-bit address bus. 5. eight additional interrupts (int2-int5, pfi, t2, and uart1). 6. variable movx timing to accommodate fast/slow ram peripherals. 7. 3.3v operation.
ez-usb technical reference manual page 2-2 ez-usb technical reference manual v1.10 2.3 ez-usb enhancements the ez-usb chip provides additional enhancements outside the 8051. these include: ? fast external transfers (autopointer, fast transfer mode) ? vectored usb interrupts (autovector) ? separate buffers for setup and data portions of a control transfer. ? breakpoint facility. 2.4 ez-usb register interface the 8051 communicates with the ez-usb core through a set of memory mapped registers. these registers are grouped as follows: ? endpoint buffers and fifos ? 8051 control ?io ports ? fast transfer ?i 2 c controller ? interrupts ? usb functions these registers and their functions are described throughout this manual. a full description of every register and bit appears in chapter 12, ?ez-usb registers.?
chapter 2. ez-usb cpu page 2-3 2.5 ez-usb internal ram figure 2-1. 8051 registers like the standard 8051, the ez-usb 8051 core contains 128 bytes of register ram at 00-7f, and a partially populated sfr register space at 80-ff. an additional 128 indirectly addressed registers (sometimes called ?idata?) are also available at 80-ff. all internal ez-usb ram, which includes program/data memory, bulk endpoint buffer memory, and the ez-usb register set, is addressed as add-on 8051 memory. the 8051 reads or writes these bytes as data using the movx (move external) instruction. even though the movx instruction implies external memory, the ez-usb ram and register set is actually inside the ez-usb chip. external memory attached to the an2131q address and data busses can also be accessed by the movx instruction. the ez-usb core encodes its memory strobe and select signals (rd#, wr#, cs#, and oe#) to eliminate the need for external logic to separate the internal and external mem- ory spaces. 2.6 i/o ports a standard 8051 communicates with its io ports 0-3 through four special function registers (sfrs). standard 8051 io pins are quasi-bidirectional with weak pullups that briefly drive high only when the pin makes a zero-to-one transition. the ez-usb core implements io ports differently than a standard 8051 , as described in chapter 4, "ez-usb input/output." instead of using the 8051 io ports and sfrs, the ez-usb core implements a flexible io system that is controlled via ez-usb register set. each ez-usb io pin functions identically, having the following resources: ? an output latch. used when the pin is an output port. ? a bit that indicates the state of the io pin, regardless of its configuration (input or output). ? an output enable bit that causes the io pin to be driven from the output latch. lower 128 bytes direct addr sfr space direct addr upper 128 bytes indirect addr 00 7f 80 ff
ez-usb technical reference manual page 2-4 ez-usb technical reference manual v1.10 ? an alternate function bit that determines whether the pin is general io or a special 8051 or ez-usb function. the sfrs associated with 8051 ports 0-3 are not implemented in ez-usb. these sfr addresses include p0 (0x80), p1 (0x90), p2 (0xa0), and p3 (0xb0). because p2 is not implemented, the movx@r0/r1 instruction takes the upper address byte from an added special function register (sfr) at location 0x92. this register is called ?mpage? in the appendices.
chapter 2. ez-usb cpu page 2-5 2.7 interrupts all standard 8051 interrupts are supported in the enhanced 8051 core. table 2-1 shows the exist- ing and added 8051 interrupts, and indicates how the added ones are used. the ez-usb chip uses 8051 int2 for 21 different usb interrupts: 16 bulk endpoints plus sof, suspend, setup data, setup token, and usb bus reset. to help the 8051 determine which interrupt is active, the ez-usb core provides a feature called autovectoring. the core inserts an address byte into the low byte of the 3-byte jump instruction found at the 8051 int2 vector address. this second level of vectoring automatically transfers control to the appropriate usb isr. the autovector mechanism, as well as the ez-usb interrupt system is the subject of chapter 9, "ez-usb interrupts." 2.8 power control the ez-usb core implements a power-down mode that allows it to be used in usb bus powered devices that must draw no more than 500 a when suspended. power control is accomplished using a combination of 8051 and ez-usb core resources. the mechanism by which ez-usb powers down for suspend, and then re-powers to resume operation, is described in detail in chap- ter 11, ?ez-usb power management.? table 2-1. ez-usb interrupts standard 8051 interrupts enhanced 8051 interrupts used as int0 device pin int0# int1 device pin int1# timer 0 internal, timer 0 timer 1 internal, timer 1 tx0 & rx0 internal, uart0 int2 internal, usb int3 internal, i 2 c controller int4 device pin, pb4/int4 int5 device pin, pb5/int5# int6 device pin, pb6/int6 pf1 device pin, usb wakeup# tx1 & rx1 internal, uart1 timer 2 internal, timer 2
ez-usb technical reference manual page 2-6 ez-usb technical reference manual v1.10 a suspend operation uses three 8051 resources, the idle mode and two interrupts. many enhanced 8051 architectures provide power control similar (or identical) to the ez-usb enhanced 8051 core. a usb suspend operation is indicated by a lack of bus activity for 3 ms. the ez-usb core detects this, and asserts an interrupt request via the usb interrupt (8051 int2). the isr (interrupt ser- vice routine) turns off external sub-systems that draw power. when ready to suspend operation, the 8051 sets an sfr bit, pcon.0. this bit causes the 8051 to suspend, waiting for an interrupt. when the 8051 sets pcon.0, a control signal from the 8051 to the ez-usb core causes the core to shut down the 12-mhz oscillator and internal pll. this stops all internal clocks to allow the ez- usb core and 8051 to enter a very low power mode. the suspended ez-usb chip can be awakened two ways: usb bus activity may resume, or an ez-usb pin (wakeup#) can be asserted to activate a usb remote wakeup . either event trig- gers the following chain of events: ? the ez-usb core re-starts the 12-mhz oscillator and pll, and waits for the clocks to sta- bilize ? the ez-usb core asserts a special, high-priority 8051 interrupt to signal a ?resume? inter- rupt. ? the 8051 vectors to the resume isr, and upon completion resumes executing code at the instruction following the instruction that set the pcon.0 bit to 1. 2.9 sfrs the ez-usb family was designed to keep 8051 coding as standard as possible, to allow easy inte- gration of existing 8051 software development tools. the added 8051 sfr registers and bits are summarized in table 2-2. table 2-2. added registers and bits 8051 enhancements sfr addr function dual data pointers dpl0 0x82 data pointer 0 low addr dph0 0x83 data pointer 0 high addr dpl1 0x84 data pointer 1 low addr dph1 0x85 data pointer 1 high addr dps 0x86 data pointer select (lsb)
chapter 2. ez-usb cpu page 2-7 2.10 internal bus members of the ez-usb family that provide pins to expand 8051 memory provide separate non- multiplexed 16-bit address and 8-bit data busses. this differs from the standard 8051, which mul- tiplexes eight device pins between three sources: io port 0, the external data bus, and the low byte of the address bus. a standard 8051 system with external memory requires a de-multiplexing address latch, strobed by the 8051 ale (address latch enable) pin. the external latch is not required by the non-multiplexed ez-usb chip, and no ale signal is needed. in addition to elimi- mpage 0x92 replaces standard 8051 port 2 for indirect external data memory addressing timer 2 t2con.6 -7 0xc8 timer 2 control rcap2l 0xca t2 capture/reload value l rcap2h 0xcb t2 capture/reload value h t2l 0xcc t2 count l t2h 0xcd t2 count h ie.5 0xa8 et2-enable t2 interrupt bit ip.5 0xb8 pt2-t2 interrupt priority control uart1 scon1. 0-1 0xc0 serial port 1 control sbuf1 0xc1 serial port 1 data ie.6 0xa8 es1-sio1 interrupt enable bit ip.6 0xb8 ps1-sio1 interrupt priority control eicon.7 0xd8 smod1-sio1 baud rate doubler interrupts int2-int5 exif 0x91 int2-int5 interrupt flags eie 0xe8 int2-int5 interrupt enables eip.0-3 0xf8 int2-int5 interrupt priority control int6 eicon.3 0xd8 int6 interrupt flag eie.4 0xe8 int6 interrupt enable eip.4 0xf8 int6 interrupt priority control wakeup# eicon.4 0xd8 wakeup# interrupt flag eicon.5 0xd8 wakeup# interrupt enable idle mode pcon.0 0x87 ez-usb power down (suspend) table 2-2. added registers and bits (continued) 8051 enhancements sfr addr function
ez-usb technical reference manual page 2-8 ez-usb technical reference manual v1.10 nating the customary external latch, the non-multiplexed bus saves one cycle per memory fetch cycle, further improving 8051 performance. a standard 8051 user must choose between using port 0 as a memory expansion port or an io port. the an2131q provides a separate io system with its own control registers (in external memory space), and provides the io port signals on dedicated (not shared) pins. this allows the external data bus to be used to expand memory without sacrificing io pins. the 8051 is the sole master of the memory expansion bus. it provides read and write signals to external memory. the address bus is output-only. a special fast transfer mode gives the ez-usb family the capability to transfer data to and from external memory over the expansion bus using a single movx instruction, which takes only two cycles (eight clocks) per byte. 2.11 reset the internal 8051 reset signal is not directly controlled by the ez-usb reset pin. instead, it is controlled by an ez-usb register bit accessible to the usb host. when the ez-usb chip is pow- ered, the 8051 is held in reset. using the default usb device (enumerated by the usb core), the host downloads code into ram. finally, the host clears an ez-usb register bit that takes the 8051 out of reset. the ez-usb family also operates with external non-volatile memory, in which case the 8051 exits the reset state automatically at power-on. the various ez-usb resets and their effects are described in chapter 10, "ez-usb resets."
chapter 3. ez-usb memory page 3-1 chapter 3 ez-usb memory 3.1 introduction ez-usb devices divide ram into two regions, one for code and data, and the other for usb buffers and control registers. figure 3-1. ez-usb 8-kb memory map - addresses are in hexadecimal 1b40/7b40 data (rd/wr) ram code(psen) ram if ea=0 (6,976 bytes) registers/bulk buffers 7fff 7b40 0000 16 x 64-byte bulk endpoint buffers (1,024 bytes) usb control registers (192 bytes) 1f40/7f40 1fff/7fff 1f3f/7f3f 1b3f data (rd/wr) ram if isodisab=1 2000 27ff registers/bulk buffers 1fff 1b40
ez-usb technical reference manual page 3-2 ez-usb technical reference manual v1.10 figure 3-2. ez-usb 4-kb memory map - addresses are in hexadecimal 3.2 8051 memory figure 3-1 illustrates the two internal ez-usb ram regions. 6,976 bytes of general-purpose ram occupy addresses 0x0000-0x1b3f. this ram is loadable by the ez-usb core or i 2 c bus eeprom, and contains 8051 code and data. the ez-usb ea (external access) pin controls where the bottom segment of code (psen) mem- ory is located?inside (ea=0) or outside (ea=1) the ez-usb chip. if the ez pin is tied low, the ez- usb core internally ors the two 8051 read signals psen and rd for this region, so that code and data share the 0x0000-0x1b3f memory space. if ea=1, all code (psen) memory is external. 1,024 bytes of ram at 0x7b40-0x7f3f implement the sixteen bulk endpoint buffers. 192 addi- tional bytes at 0x7f40-0x7fff contain the usb control registers. the 8051 reads and writes this memory using the movx instruction. in the 8-kb ram ez-usb version, the 1,024 bulk endpoint buffer bytes at 0x7b40-0x7f3f also appear at 0x1b40-0x1f3f. this aliasing allows unused bulk about 8051 memory spaces the 8051 partitions its memory spaces into code memory and data memory. the 8051 reads code memory using the signal psen# (program store enable), reads data memory using the signal rd# (data read) and writes data memory using the signal wr# (data write). the 8051 movx (move external) instruction generates rd# or wr# strobes. psen# is a dedicated pin, while the rd# and wr# signals share pins with two io port signals: pc7/rd and pc6/wr. therefore, if expanded memory is used, the port pins pc7 and pc6 are not available to the system. 7c00 code(psen) and data (rd/wr) ram (4096 bytes) registers/bulk buffers 7fff 7b40 0000 13 x 64-byte bulk endpoint buffers (832 bytes) usb control registers (192 bytes) 7f40 7fff 7f3f 0fff
chapter 3. ez-usb memory page 3-3 endpoint buffer memory to be added contiguously to the data memory, as illustrated figure 3-3. the memory space at 0x1f40-0x1fff should not be used. even though the 8051 can access ez-usb endpoint buffers at either 0x1b40 or 0x7b40, the firm- ware should be written to access this memory only at 0x7b40-0x7fff to maintain compatibility with future versions of ez-usb that contain more than 8 kb of ram. future versions will have the bulk buffer space at 0x7b40-0x7f3f only. figure 3-3. unused bulk endpoint buffers (shaded) used as data memory in the example shown in figure 3-3, only endpoints 0-in through 3-in are used for the usb func- tion, so the data ram (shaded) can be extended to 0x1d7f. if an application uses none of the 16 ez-usb isochronous endpoints, the 8051 can set the iso- disab bit in the isoctl register to disable all 16 isochronous endpoints, and make the 2-kb of isochronous fifo ram available as 8051 data ram at 0x2000-0x27ff. setting isodisab=1 is an all or nothing choice, as all 16 isochronous endpoints are disabled. an application that sets this bit must never attempt to transfer data over an isochronous endpoint. the memory map figures in the remainder of this chapter assume that isodisab=0, the default (and normal) case. ep0in ep0out ep1in ep1out ep2in ep2out ep3in ep3out ep4in ep4out ep5in ep5out ep6in ep06ut ep7in ep07out 1b40 code/data ram 0000 1b3f 1b80 1bc0 1c00 1c40 1c80 1cc0 1d00 1d40 1d80 1dc0 1e00 1e40 1e80 1ec0 1f00 1f40
ez-usb technical reference manual page 3-4 ez-usb technical reference manual v1.10 3.3 expanding ez-usb memory the 80-pin ez-usb package provides a 16-bit address bus, an 8-bit bus, and memory control sig- nals psen#, rd#, and wr#. these signals are used to expand ez-usb memory. figure 3-4. ez-usb memory map with ea=0 figure 3-4 shows that when ea=0, the code/data memory is internal at 0x0000-0x1b40. external code memory can be added from 0x0000-0xffff, but it appears in the memory map only at 0x1b40-0xffff. addressing external code memory at 0x0000-0x1b3f when ea=0 causes the ez-usb core to inhibit the #psen strobe. this allows program memory to be added from 0x0000- 0xffff without requiring decoding to disable it between 0x0000 and 0x1b3f. code & data (psen,rd,wr) registers(rd,wr) external code memory (psen) external data memory (rd, wr) external data memory (rd,wr) 1b40 inside ez-usb outside ez-usb 8000 7b40 0000 1f3f ffff (note 2) note 1: ok to populate data memory here--rd#, wr#, cs# and oe# pins are inactive. (note 1) unused bulk buffers (rd,wr) note 2: ok to populate code memory here--no psen# strobe is generated. (note 1) 1fff 2000
chapter 3. ez-usb memory page 3-5 the internal block at 0x7b40-0x7fff (labeled ?registers?) contains the bulk buffer memory and ez-usb control registers. as previously mentioned, they are aliased at 0x1b40-0x1fff to allow adding unused bulk buffer ram to general-purpose memory. 8051 code should access this mem- ory only at the 0x7b40-0x7bff addresses. external ram may be added from 0x0000 to 0xffff, but the regions shown by note 1 in figure 3-4 are ignored; no external strobes or select signals are generated when the 8051 executes a movx instruction that addresses these regions. 3.4 cs# and oe# signals the ez-usb core automatically gates the standard 8051 rd# and wr# signals to exclude selec- tion of external memory that exists internal to the ez-usb part. the psen# signal is also avail- able on a pin for connection to external code memory. some 8051 systems implement external memory that is used as both data and program memory. these systems must logically or the psen# and rd# signals to qualify the chip enable and out- put enable signals of the external memory. to save this logic, the ez-usb core provides two addi- tional control signals, cs# and oe# : ? cs# goes low when rd#, wr#, or psen# goes low ? oe# goes low when rd# or psen# goes low because the rd#, wr#, and psen# signals are already qualified by the addresses allocated to external memory, these strobes are active only when external memory is accessed.
ez-usb technical reference manual page 3-6 ez-usb technical reference manual v1.10 figure 3-5. ez-usb memory map with ea=1 when ea=1 (figure 3-5), all code (psen) memory is external. all internal ez-usb ram is data memory. this gives the user over 6-kb of general-purpose ram, accessible by the movx instruction. note figures 3-4 and 3-5 assume that the ez-usb chip uses isochronous endpoints, and therefore that the isodisab bit (isoctl.0) is lo. if isodisab=1, additional data ram appears internally at 0x2000-0x27ff, and the rd#, wr#, cs#, and oe# signals are modified to exclude this mem- ory space from external data memory. data (rd,wr) registers(rd,wr) external code memory (psen) external data memory (rd, wr) external data memory (rd,wr) 1b40 inside ez-usb outside ez-usb 8000 7b40 0000 1f3f ffff note 1: ok to populate data memory here--rd#, wr#, cs# and oe# are inactive. (note 1) unused bulk buffers (rd,wr) (note 1) 1fff 2000
chapter 4. ez-usb input/output page 4-1 chapter 4 ez-usb input/output 4.1 introduction the ez-usb chip provides two input-output systems: ? a set of programmable io pins ? a programmable i 2 c controller this chapter begins with a description of the programmable io pins, and shows how they are shared by a variety of 8051 and ez-usb alternate functions such as uart, timer and interrupt sig- nals. the i 2 c controller uses the scl and sda pins, and performs two functions: ? general-purpose 8051 use ? boot loading from an eeprom this chapter describes both the programming information for the 8051 i 2 c interface, and the oper- ating details of the i 2 c boot loader. the role of the boot loader is described in chapter 5, "ez-usb enumeration and renumeration?." note 2.2-kb to 4.7-kb pullups are required on the sda and scl lines.
ez-usb technical reference manual page 4-2 ez-usb technical reference manual v1.10 4.2 io ports figure 4-1. ez-usb input/output pin the ez-usb family implements its io ports using memory-mapped registers. this is in contrast to a standard, which uses sfr bits for input/output. figure 4-1 shows the basic structure of an ez-usb io pin. twenty-four io pins are grouped into three 8-bit ports named porta, portb, and portc. the an2131q has all three ports, while the an2131s has portb, portc, and two porta bits. the 8051 accesses io pins using the three control bits shown in figure 4-1: oe, out, and pins. the out bit writes output data to a register, the oe bit turns on the output buffer, and the pins bit indicates the state of the pin. to configure a pin as an input, the 8051 sets oe=0 to turn off the output buffer. to configure a pin as an output, the 8051 sets oe=1 to turn on the output buffer, and writes data to the out register. the pins bit reflects the actual pin value regardless of the value of oe. a fourth control bit (in portacfg, portbcfg, portccfg registers) determines whether a port pin is general-purpose input/output (gpio) as shown in figure 4-1, or connected to an alter- nate 8051 or ez-usb function. table 4-1 lists the alternate functions available on the io pins. figure 4-1 shows the registers and bits associated with the io ports. table 4-1. io pin functions for portxcfg=0 and portxcfg=1 portxcfg bit = 0 portxcfg bit = 1 signal signal direction description figure pa0 t0out out timer 0 overflow pulse 4-2 pa1 t1out out timer 1 overflow pulse 4-2 pa2 oe# out ez-usb output enable 4-2 pa3 cs# out ez-usb chip select 4-2 pa4 fwr# out ez-usb fast write strobe 4-2 reg out pin pins oe
chapter 4. ez-usb input/output page 4-3 depending on whether the alternate function is an input or output, the io logic is slightly different, as shown in figure 4-2 (output) and figure 4-3 (input). the last column of table 4-1 indicates which figure applies to each pin. pa5 frd# out ez-usb fast read strobe 4-2 pa6 rxd0ou t out uart0 mode 0 data out 4-2 pa7 rxd1ou t out uart1 mode 0 data out 4-2 pb0 t2 in timer 2 clock input 4-3 pb1 t2ex in timer 2 capture/reload 4-3 pb2 rxd1 in uart1 receive data 4-3 pb3 txd1 out uart1 transmit data 4-2 pb4 int4 in interrupt 4 4-3 pb5 int5 in interrupt 5 4-3 pb6 int6 in interrupt 6 4-3 pb7 t2out out timer 2 overflow pulse 4-2 pc0 rxd0 in uart0 receive data 4-3 pc1 txd0 out uart0 transmit data 4-2 pc2 int0# in interrupt 0 4-3 pc3 int1# in interrupt 1 4-3 pc4 t0 in timer 0 clock input 4-3 pc5 t1 in timer 1 clock input 4-3 pc6 wr# out write strobe 4-2 pc7 rd# out read strobe 4-2 table 4-1. io pin functions for portxcfg=0 and portxcfg=1 (continued) portxcfg bit = 0 portxcfg bit = 1 signal signal direction description figure
ez-usb technical reference manual page 4-4 ez-usb technical reference manual v1.10 figure 4-2. alternate function is an output referring to figure 4-2, when portcfg=0, the io port is selected. in this case the alternate function (shaded) is disconnected and the pin functions exactly as shown in figure 4-1. when portcfg=1, the alternate function is connected to the io pin and the output register and buffer are disconnected. note that the 8051 can still read the state of the pin, and thus the alternate function value. figure 4-3. alternate function is an input referring to figure 4-3, when portcfg=0, the io port is selected. this is the general io port shown in figure 4-1 with one important difference?the alternate function is always listening . whether the port pin is set for output or input, the pin signal also drives the alternate function. 8051 firmware should ensure that if the alternate function is not used (if the pin is gpio only), the alternate input function is disabled. for example, suppose the pb4/int4 pin is configured for pb4. the pin signal is also routed to int4. if int4 is not used by the application, it should not be enabled. alternatively, enabling int4 could be useful, allowing io bit pb4 to trigger an interrupt. when portxcfg=1, the alternate function is selected. the output register and buffer are discon- nected. the pins bit can still read the pin, and thus the input to the alternate function. reg out pin pins oe alternate function output out pins alternate function output oe reg pin portcfg=0 (p ort ) portcfg=1 ( alternate function ) reg out pin pins oe alternate function input out pins alternate function input oe reg pin portcfg=0 (port) portcfg=1 (alternate function)
chapter 4. ez-usb input/output page 4-5 4.3 io port registers figure 4-4. registers associated with ports a, b, and c figure 4-4 shows the registers associated with the ez-usb io ports. the power-on default for the portcfg bits is 0, selecting the io port function. the power-on default for the oe bits is 0, selecting the input direction. rxd1out rxd0out frd fwr cs oe t1out t0out portacfg d7 d6 d5 d4 d3 d2 d1 d0 outa pinsa oea t2out int6 int5 int4 txd1 rxd1 t2ex t2 portbcfg outb pinsb oeb rd wr t1 t0 int1 int0 txd0 rxd0 portccfg outc pinsc oec d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d2 d1 d0
ez-usb technical reference manual page 4-6 ez-usb technical reference manual v1.10 4.4 i 2 c controller the usb core contains an i 2 c controller for boot loading and general-purpose i 2 c bus interface. this controller uses the scl (serial clock) and sda (serial data) pins. i2c controller describes how the boot load operates at power-on to read the contents of an external serial eeprom to determine the initial ez-usb fx configuration. the boot loader operates automatically, while the 8051 is held in reset. the last section of this chapter describes the operating details of the boot loader. after the boot sequence completes and the 8051 is brought out of reset, the general-purpose i 2 c controller is available to the 8051 for interface to external i 2 c devices, such as other eeproms, i/ o chips, audio/video control chips, etc. 4.5 8051 i 2 c controller figure 4-5. general i 2 c transfer figure 4-5 illustrates the waveforms for an i 2 c transfer. scl and sda are open-drain ez-usb pins, which must be pulled up to vcc with external resistors. the ez-usb chip is an i 2 c bus mas- ter only, meaning that it synchronizes data transfers by generating clock pulses on scl by driving low. once the master drives scl low, external slave devices can also drive scl low to extend clock cycle times. to synchronize i 2 c data, serial data (sda) is permitted to change state only while scl is low, and must be valid while scl is high. two exceptions to this rule are used to generate start and stop conditions. a start condition is defined as sda going low, while scl is high, and a stop condition is defined as sda going high, while scl is high. data is sent msb first. during the last bit time (clock #9 in figure 4-5), the master (ez-usb) floats the sda line to allow the slave to acknowledge the transfer by pulling sda low. 123456 7 8 9 d7 ack d6 d5 d4 d3 d2 d1 d0 start stop sda scl
chapter 4. ez-usb input/output page 4-7 figure 4-6. addressing an i 2 c peripheral the first byte of an i 2 c bus transaction contains the address of the desired peripheral. figure 4-7 shows the format for this first byte, which is sometimes called a control byte. a master sends the bit sequence shown in figure 4-6 after sending a start condition. the mas- ter uses this 9-bit sequence to select an i 2 c peripheral at a particular address, to establish the transfer direction (using r/w#), and to determine if the peripheral is present by testing for ack#. the four most significant bits sa3-sa0 are the peripheral chip?s slave address. i 2 c devices are pre-assigned slave addresses by device type, for example slave address 1010 is assigned to eeproms. the three bits da2-da0 usually reflect the states of i 2 c device address pins. devices with three address pins can be strapped to allow eight distinct addresses for the same device type. the eighth bit (r/w#) sets the direction for the ensuing data transfer, 1 for master read, and 0 for master write. most address transfers are followed by one or more data transfers, with the stop condition generated after the last data byte is transferred. in figure 4-6, a read transfer follows the address byte (at clock 8, the master sets the r/w# bit high, indicating read). at clock 9, the peripheral device responds to its address by asserting ack. at clock 10, the master floats sda and issues scl pulses to clock in sda data supplied by this slave. assuming the 12-mhz crystal used by the ez-usb family, the scl frequency is 90.9 khz, giving an i 2 c transfer rate of 11 ms per bit. multiple i 2 c bus masters ? the ez-usb chip acts only as an i 2 c bus master, never a slave. however, the 8051 can detect a second master by checking for berr=1 (section 4.7, "status bits"). 123456 7 8 9 sa3 ack sa2 sa1 sa0 da2 da1 da0 start sda d7 d6 10 11 r/w scl
ez-usb technical reference manual page 4-8 ez-usb technical reference manual v1.10 figure 4-7. fc registers the 8051 uses the two registers shown in figure 4-7 to conduct i 2 c transfers. the 8051 transfers data to and from the i 2 c bus by writing and reading the i2dat register. the i2cs register controls i 2 c transfers and reports various status conditions. the three control bits are start, stop, and lastrd. the remaining bits are status bits. writing to a status bit has no effect. 4.6 control bits 4.6.1 start the 8051 sets the start bit to 1 to prepare an i 2 c bus transfer. if start=1, the next 8051 load to i2dat will generate the start condition followed by the serialized byte of data in i2dat. the 8051 loads data in the format shown in figure 4-5 after setting the start bit. the i 2 c controller clears the start bit during the ack interval (clock 9 in figure 4-5). 4.6.2 stop the 8051 sets stop=1 to terminate an i 2 c bus transfer. the i 2 c controller clears the stop bit after completing the stop condition. if the 8051 sets the stop bit during a byte transfer, the stop condition will be generated immediately following the ack phase of the byte transfer. if no byte transfer is occurring when the stop bit is set, the stop condition will be carried out immedi- ately on the bus. data should not be written to i2cs or i2dat until the stop bit returns low. in the 2122/2126 only, an interrupt request is available to signal that stop bit transmission is com- plete. i2cs i 2 c control and status 7fa5 b7 b6 b5 b4 b3 b2 b1 b0 start stop lastrd id1 id0 berr ack done i2dat i 2 c data 7fa6 b7 b6 b5 b4 b3 b2 b1 b0 d7 d6 d5 d4 d3 d2 d1 d0
chapter 4. ez-usb input/output page 4-9 4.6.3 lastrd to read data over the i 2 c bus, an i 2 c master floats the sda line and issues clock pulses on the scl line. after every eight bits, the master drives sda low for one clock to indicate ack. to sig- nal the last byte of the read transfer, the master floats sda at ack time to instruct the slave to stop sending. this is controlled by the 8051 by setting lastrd=1 before reading the last byte of a read transfer. the i 2 c controller clears the lastrd bit at the end of the transfer (at ack time). 4.7 status bits after a byte transfer the ez-usb controller updates the three status bits berr, ack, and done. if no stop condition was transmitted, they are updated at ack time. if a stop condition was transmitted they are updated after the stop condition is transmitted. 4.7.1 done the i 2 c controller sets this bit whenever it completes a byte transfer, right after the ack stage. the controller also generates an i 2 c interrupt request (8051 int3) when it sets the done bit. the i 2 c controller clears the done bit when the 8051 reads or writes the i2dat register, and the i 2 c interrupt request bit whenever the 8051 reads or writes the i2cs or i2dat register. 4.7.2 ack every ninth scl of a write transfer, the slave indicates reception of the byte by asserting ack. the ez-usb controller floats sda during this time, samples the sda line, and updates the ack bit with the complement of the detected value. ack=1 indicates acknowledge, and ack=0 indicates not-acknowledge. the ez-usb core updates the ack bit at the same time it sets done=1. the ack bit should be ignored for read transfers on the bus. 4.7.3 berr this bit indicates an i 2 c bus error. berr=1 indicates that there was bus contention, which results when an outside device drives the bus lo when it shouldn?t, or when another bus master wins note setting lastrd does not automatically generate a stop condition. the 8051 should also set the stop bit at the end of a read transfer.
ez-usb technical reference manual page 4-10 ez-usb technical reference manual v1.10 arbitration, taking control of the bus. berr is cleared when the 8051 reads or writes the i2dat register. 4.7.4 id1, id0 these bits are set by the boot loader (section 4.10, "i 2 c boot loader") to indicate whether an 8-bit address or 16-bit address eeprom at slave address 000 or 001 was detected at power-on. they are normally used only for debug purposes. table 4-3 shows the encoding for these bits. 4.8 sending i 2 c data to send a multiple byte data record over the i 2 c bus, follow these steps: 1. set the start bit. 2. write the peripheral address and direction=0 (for write) to i2dat. 3. wait for done=1*. if berr=1 or ack=0, go to step 7. 4. load i2dat with a data byte. 5. wait for done=1*. if berr=1 or ack=0 go to step 7. 6. repeat steps 4 and 5 for each byte until all bytes have been transferred. 7. set stop=1. * if the i 2 c interrupt (8051 int3) is enabled, each ?wait for done=1? step can be interrupt driven, and handled by an interrupt service routine. see section 9.12, "i2c interrupt", for more details regarding the i 2 c interrupt. 4.9 receiving i 2 c data to read a multiple-byte data record, follow these steps: 1. set the start bit. 2. write the peripheral address and direction=1 (for read) to i2dat. 3. wait for done=1*. if berr=1 or ack=0, terminate by setting stop=1. 4. read i2dat and discard the data. this initiates the first burst of nine scl pulses to clock in the first byte from the slave. 5. wait for done=1*. if berr=1, terminate by setting stop=1. 6. read the data from i2dat. this initiates another read transfer. 7. repeat steps 5 and 6 for each byte until ready to read the second-to-last byte. 8. before reading the second-to-last i2dat byte, set lastrd=1. 9. read the data from i2dat. with lastrd=1, this initiates the final byte read on the i 2 c bus.
chapter 4. ez-usb input/output page 4-11 10. wait for done=1*. if berr=1, terminate by setting stop=1. 11. set stop=1. 12. read the last byte from i2dat immediately (the next instruction) after setting the stop bit. this retrieves the last data byte without initiating an extra read transaction (nine more scl pulses) on the i 2 c bus. *if the i 2 c interrupt (8051 int3) is enabled, each ?wait for done=1? step can be interrupt-driven, and handled by an inter- rupt service routing. see section 9.12, "i2c interrupt" for more details regarding the i 2 c interrupt. 4.10 i 2 c boot loader when the ez-usb chip comes out of reset, the ez-usb boot loader checks for the presence of an eeprom on its i 2 c bus. if an eeprom is detected, the loader reads the first eeprom byte to determine how to enumerate (specifically, whether to supply id information from the ez-usb core or from the eeprom). the various enumeration modes are described in chapter 5, "ez-usb enumeration and renumeration?". prior to reading the first eeprom byte, the boot loader must set an address counter inside the eeprom to zero. it does this by sending a control byte (write) to select the eeprom, followed by a zero address to set the internal eeprom address pointer to zero. then it issues a control byte (read), and reads the first eeprom byte. the ez-usb boot loader supports two i 2 c eeprom types: ? eeproms with address a[7..4]=1010 that use an 8-bit address (example: 24lc00, lc01/ a, lc02/a). ? eeproms with address a[7..4]=1010 that use a 16-bit address (example: 24aa64, 24lc128, 24aa256). eeproms with densities up to 256 bytes require loading a single address byte. larger eeproms require loading two address bytes. the ez-usb i 2 c controller needs to determine which eeprom type is connected?one or two address bytes?so that it can properly reset the eeprom address pointer to zero before reading the eeprom. for the single-byte address part, it must send a single zero byte of address, and for the two-byte address part it must send two zero bytes of address. because there is no direct way to detect which eeprom type?single or double address?is con- nected, the i 2 c controller uses the eeprom address pins a2, a1, and a0 to determine whether to send out one or two bytes of address. this algorithm requires that the eeprom address lines are strapped as shown in table 4-2. single-byte-address eeproms are strapped to address 000 and double-byte-address eeproms are strapped to address 001.
ez-usb technical reference manual page 4-12 ez-usb technical reference manual v1.10 * this eeprom does not have address pins the i 2 c controller performs a three-step test at power-on to determine whether a one-byte- address or a two-byte-address eeprom is attached. this test proceeds as follows: 1. the i 2 c controller sends out a ?read current address? command to i 2 c sub-address 000 (10100001). if no ack is returned, the controller proceeds to step 2. if ack is returned, the one-byte-address device is indicated. the controller discards the data and proceeds to step 3. 2. the i 2 c controller sends out a ?read current address? command to i 2 c sub-address 001 (10100011). if ack is returned, the two-byte-address device is indicated. the controller dis- cards the data and proceeds to step 3. if no ack is returned, the controller assumes that a valid eeprom is not connected, assumes the ?no serial eeprom? mode, and terminates the boot load. 3. the i 2 c controller resets the eeprom address pointer to zero (using the appropriate number of address bytes), then reads the first eeprom byte. if it does not read 0xb0 or 0xb2, the controller assumes the ?no serial eeprom? mode. if it reads either 0xb0 or 0xb2, the con- troller copies the next six bytes into internal storage, and if it reads 0xb2, it proceeds to load the eeprom contents into internal ram. the results of this power-on test are reported in the id1 and id0 bits, as shown in table 4-3. other eeprom devices (with device address of 1010) can be attached to the i 2 c bus for general purpose 8051 use, as long as they are strapped for address other than 000 or 001. if a 24lc00 eeprom is used, no other eeproms with device address 1010 may be used, because the 24lc00 responds to all eight sub-addresses. table 4-2. strap boot eeprom address lines to these values bytes example eeprom a2 a1 a0 16 24lc00* n/a n/a n/a 128 24lc01 0 0 0 256 24lc02 0 0 0 4k 24lc32 0 0 1 8k 24lc64 0 0 1 table 4-3. results of power-on i 2 c test id1 id0 meaning 0 0 no eeprom detected 0 1 one-byte-address load eeprom detected 1 0 two-byte-address load eeprom detected 1 1 not used
chapter 5. ez-usb enumeration and renumeration? page 5-1 chapter 5 ez-usb enumeration and renumeration? 5.1 introduction the ez-usb chip is soft . 8051 code and data is stored in internal ram, which is loaded from the host using the usb interface. peripheral devices that use the ez-usb chip can operate without rom, eprom, or flash memory, shortening production lead times and making firmware updates a breeze. to support the soft feature, the ez-usb chip automatically enumerates as a usb device without firmware , so the usb interface itself may be used to download 8051 code and descriptor tables. the ez-usb core performs this initial (power-on) enumeration and code download while the 8051 is held in reset. this initial usb device, which supports code download, is called the ?default usb device.? after the code descriptor tables have been downloaded from the host to ez-usb ram, the 8051 is brought out of reset and begins executing the device code. the ez-usb device enumerates again, this time as the loaded device. this second enumeration is called ?renumeration ? ,? which the ez-usb chip accomplishes by electrically simulating a physical disconnection and re-connec- tion to the usb. an ez-usb control bit called ?renum? (renumerated) determines which entity, the core or the 8051, handles device requests over endpoint zero. at power-on, the renum bit (usbcs.1) is zero, indicating that the ez-usb core automatically handles device requests. once the 8051 is running, it can set renum=1 to indicate that user 8051 code handles subsequent device requests using its downloaded firmware. chapter 7, "ez-usb endpoint zero" describes how the 8051 han- dles device requests while renum=1. it is also possible for the 8051 to run with renum=0 and have the ez-usb core handle certain endpoint zero requests (see the text box, ?another use for the default usb device? on page 5-2). this chapter deals with the various ez-usb startup modes, and describes the default usb device that is created at initial enumeration.
ez-usb technical reference manual page 5-2 ez-usb technical reference manual v1.10 5.2 the default usb device the default usb device consists of a single usb configuration containing one interface (interface 0) with three alternate settings 0, 1, and 2. the endpoints reported for this device are shown in table 5-1. note that alternate setting zero uses no interrupt or isochronous bandwidth, as recom- mended by the usb specification. for purposes of downloading 8051 code, the default usb device requires only control end- point zero. nevertheless, the usb default machine is enhanced to support other endpoints as shown in figure 5-1 (note the alternate settings 1 and 2). this enhancement is provided to allow the developer to get a head start generating usb traffic and learning the usb system. all the another use for the default usb device the default usb device is established at power-on to set up a usb device capable of download- ing firmware into ez-usb ram. another useful feature of the ez-usb default device is that 8051 code can be written to support the already-configured generic usb device. before bring- ing the 8051 out of reset, the ez-usb core enables certain endpoints and reports them to the host via descriptors. by utilizing the usb default machine (by keeping renum=0), the 8051 can, with very little code, perform meaningful usb transfers that use these default endpoints. this accelerates the usb learning curve. to see an example of how little code is actually necessary, take a look at section 6.11, "polled bulk transfer example." table 5-1. ez-usb default endpoints endpoint type alternate setting 0 1 2 maximum packet size (bytes) 0 ctl 64 64 64 1-in int 0 16 64 2-in bulk 0 64 64 2-out bulk 0 64 64 4-in bulk 0 64 64 4-out bulk 0 64 64 6-in bulk 0 64 64 6-out bulk 0 64 64 8-in iso 0 16 256 8-out iso 0 16 256 9-in iso 0 16 16 9-out iso 0 16 16 10-in iso 0 16 16 10 out iso 0 16 16
chapter 5. ez-usb enumeration and renumeration? page 5-3 descriptors are automatically handled by the ez-usb core, so the developer can immediately start writing code to transfer data over usb using these pre-configured endpoints. when the ez-usb core establishes the default usb device, it also sets the proper endpoint con- figuration bits to match the descriptor data supplied by the ez-usb core. for example, bulk end- points 2, 4, and 6 are implemented in the default usb device, so the ez-usb core sets the corresponding epval bits. chapter 6, ?ez-bulk transfers? contains a detailed explanation of the epval bits. tables 5-9 through 5-13 show the various descriptors returned to the host by the ez-usb core when renum=0. these tables describe the usb endpoints defined in table 5-1, along with other usb details, and should be useful to help understand the structure of usb descriptors. 5.3 ez-usb core response to ep0 device requests table 5-2 shows how the ez-usb core responds to endpoint zero requests when renum=0. table 5-2. how the ez-usb core handles ep0 requests when renum=0 brequest name action: renum=0 0x00 get status/device returns two zero bytes 0x00 get status/endpoint supplies ep stall bit for indicated ep 0x00 get status/interface returns two zero bytes 0x01 clear feature/device none 0x01 clear feature/endpoint clears stall bit for indicated ep 0x02 (reserved) none 0x03 set feature/device none 0x03 set feature endpoint sets stall bit for indicated ep 0x04 (reserved) none 0x05 set address updates fnadd register 0x06 get descriptor supplies internal table 0x07 set descriptor none 0x08 get configuration returns internal value 0x09 set configuration sets internal value 0x0a get interface returns internal value (0-3) 0x0b set interface sets internal value (0-3) 0x0c sync frame none vendor requests 0x0a firmware load upload/download ram 0xa1- 0xaf reserved reserved by cypress semiconductor all other none
ez-usb technical reference manual page 5-4 ez-usb technical reference manual v1.10 the usb host enumerates by issuing: ? set_address ? get_descriptor ? set_configuration (to 1) as shown in table 5-2, after enumeration, the ez-usb core responds to the following host requests. ? set or clear an endpoint stall (set/clear feature-endpoint). ? read the stall status for an endpoint (get_status_endpoint). ? set/read an 8-bit configuration number (set/get_configuration). ? set/read a 2-bit interface alternate setting (set/get_interface). ? download or upload 8051 ram. to ensure proper operation of the default keil monitor, which uses sio-1 (rxd1 and txd1), never change the following port config bits from ?1?: ? portbcfg bits 2 (rxd1) and 3 (txd1). to ensure the 8051 processor can access the external sram (including the keil monitor), do not change the following bits from ?1?: ? portccfg bits 6 (wr#) and 7 (rd#). to ensure that no bits are unintentionally changed, all writes to the portxcfg registers should use a read-modify-write series of instructions.
chapter 5. ez-usb enumeration and renumeration? page 5-5 5.4 firmware load the usb specification provides for vendor-specific requests to be sent over control endpoint zero. the ez-usb chip uses this feature to transfer data between the host and ez-usb ram. the ez-usb core responds to two ?firmware load? requests, as shown in tables 5-3 and 5-4. these requests are always handled by the ez-usb core (renum=0 or 1). this means that 0xa0 is reserved by the ez-usb chip, and therefore should never be used for a vendor request. cypress semiconductor also reserves brequest values 0xa1 through 0xaf, so your system should not use these brequest values. table 5-3. firmware download byte field value meaning 8051 response 0 bmrequest 0x40 vendor request, out none required 1 brequest 0xa0 ?firmware load? 2 wvaluel addrl starting address 3 wvalueh addrh 4 windexl 0x00 5 windexh 0x00 6 wlenghtl lenl number of bytes 7 wlengthh lenh table 5-4. firmware upload byte field value meaning 8051 response 0 bmrequest 0xc0 vendor request, in none required 1 brequest 0xa0 ?firmware load? 2 wvaluel addrl starting address 3 wvalueh addrh 4 windexl 0x00 5 windexh 0x00 6 wlengthl lenl number of bytes 7 wlengthh lenh
ez-usb technical reference manual page 5-6 ez-usb technical reference manual v1.10 a host loader program typically writes 0x01 to the cpucs register to put the 8051 into reset, loads all or part of the ez-usb ram with 8051 code, and finally reloads the cpucs register with 0 to take the 8051 out of reset. the cpucs register is the only usb register that can be written using the firmware download command. firmware loads are restricted to internal ez-usb memory. 5.5 enumeration modes when the ez-usb chip comes out of reset, the ez-usb core makes a decision about how to enu- merate based on the contents of an external eeprom on its i 2 c bus. table 5-5 shows the choices. in table 5-5, pid means product id, vid means version id, and did means device id. if no eeprom is present, or if one is present but the first byte is neither 0xb0 nor 0xb2, the ez- usb core enumerates using internally stored descriptor data, which contains the cypress semi- conductor vid, pid, and did. these id bytes cause the host operating system to load a cypress semiconductor device driver. the ez-usb core also establishes the default usb device . this mode is only used for code development and debug. when renum=1 at power-on at power-on, the renum bit is normally set to zero so that the ez-usb handles device requests over control endpoint zero. this allows the core to download 8051 firmware and then recon- nect as the target device. at power-on, the ez-usb core checks the i 2 c bus for the presence of an eeprom. if it finds one, and the first byte of the eeprom is 0xb2, the core copies the contents of the eeprom into internal ram, sets the renum bit to 1, and un-resets the 8051. the 8051 wakes up ready-to- run firmware in ram. the required data form for this load module is described in the next section. table 5-5. ez-usb core action at power-up first eeprom byte ez-usb core action not 0xb0 or 0xb2 supplies descriptors, pid/vid/did from ez- usb core. sets renum=0. 0xb0 supplies descriptors from ez-usb core, pid/vid/did from eeprom. sets renum=0. 0xb2 loads eeprom into ez-usb ram. sets renum=1; therefore 8051 supplies descrip- tors, pid/vid/did.
chapter 5. ez-usb enumeration and renumeration? page 5-7 if a serial eeprom is attached to the i 2 c bus and its first byte is 0xb0, the ez-usb core enumer- ates with the same internally stored descriptor data as for the no-eeprom case, but with one dif- ference. it supplies the pid/vid/did data from six bytes in the external eeprom rather than from the ez-usb core. the custom vid/pid/did in the eeprom causes the host operating system to load a device driver that is matched to the eeprom vid/pid/did. this ez-usb operating mode provides a soft usb device using renumeration ?. if a serial eeprom is attached to the i 2 c bus and its first byte is 0xb2, the ez-usb core transfers the contents of the eeprom into internal ram. the ez-usb core also sets the renum bit to 1 to indicate that the 8051 (and not the ez-usb core) responds to device requests over control endpoint zero (see the text box, ?when renum=1 at power-on? on page 5-6). therefore, all descriptor data, including vid/did/pid values, are supplied by the 8051 firmware. the last byte loaded from the eeprom (to the cpucs register) releases the 8051 reset signal, allowing the ez-usb chip to come up as a fully custom device with firmware in ram. the following sections discuss these enumeration methods in detail. 5.6 no serial eeprom in the simplest case, no serial eeprom is present on the i 2 c bus, or an eeprom is present but its first byte is not 0xb0 or 0xb2. in this case, descriptor data is supplied by a table internal to the ez-usb core. the ez-usb chip comes on as the usb default device , with the id bytes shown in ta b l e 5 - 6 . the other half of the i 2 c story the ez-usb i 2 c controller serves two purposes. first, as described in this chapter, it manages the serial eeprom interface that operates automatically at power-on to determine the enumera- tion method. second, once the 8051 is up and running, the 8051 can access the i 2 c controller for general-purpose use. this makes a wide range of standard i 2 c peripherals available to an ez-usb system. other i 2 c devices can be attached to the scl and sda lines of the i 2 c bus as long as there is no address conflict with the serial eeprom described in this chapter. chapter 4, "ez-usb input/ output" describes the general-purpose nature of the i 2 c interface. table 5-6. ez-usb device characteristics, no serial eeprom vendor id 0x0547 (cypress semiconductor) product id 0x2131 (ez-usb) device release 0xxxyy (depends on revision)
ez-usb technical reference manual page 5-8 ez-usb technical reference manual v1.10 the usb host queries the device during enumeration, reads the device descriptor, and uses the table 5-6 bytes to determine which software driver to load into the operating system. this is a major usb feature?drivers are dynamically matched with devices and automatically loaded when a device is plugged in. the no_eeprom case is the simplest configuration, but also the most limiting. this mode is used only for code development, utilizing cypress software tools matched to the id values in table 5-6. 5.7 serial eeprom present, first byte is 0xb0 if, at power-on, the ez-usb core detects an eeprom connected to its i 2 c port with the value 0xb0 at address 0, the ez-usb core copies the vendor id (vid), product id (pid), and device id (did) from the eeprom (table 5-7) into internal storage. the ez-usb core then supplies these bytes to the host as part of the get_descriptor-device request. (these six bytes replace only the vid/pid/did bytes in the default usb device descriptor.) this causes a driver matched to the vid/pid/did values in the eeprom, instead of those in the ez-usb core, to be loaded into the os. after initial enumeration, the driver downloads 8051 code and usb descriptor data into ez-usb ram and starts the 8051. the code then renumerates ? to come on as the fully custom device. a recommended eeprom for this application is the microchip 24lc00, a small (5-pin sot pack- age) inexpensive 16-byte serial eeprom. a 24lc01 (128 bytes) or 24lc02 (256 bytes) may be substituted for the 24lc00, but as with the 24lc00, only the first seven bytes are used. reminder the ez-usb core uses the table 5-6 data for enumeration only if the renum bit is zero. if renum=1, enumeration data is supplied by 8051 code. table 5-7. eeprom data format for ?b0? load eeprom address contents 0 0xb0 1 vendor id (vid) l 2 vendor id (vid) h 3 product id (pid) l 4 product id (pid) h 5 device id (did) l 6 device id (did) h 7 not used
chapter 5. ez-usb enumeration and renumeration? page 5-9 5.8 serial eeprom present, first byte is 0xb2 if, at power-on, the ez-usb core detects an eeprom connected to its i 2 c port with the value 0xb2 at address 0; the ez-usb core loads the eeprom data into ez-usb ram. it also sets the renum bit to 1, causing device requests to be fielded by the 8051 instead of the ez-usb core. the eeprom data format is shown in table 5-8. the first byte tells the ez-usb core to copy eeprom data into ram. the next six bytes (1-6) are ignored (see the text box, ?vid/pid/did in a ?b2? eeprom? on page 5-10). table 5-8. eeprom data format for ?b2? load eeprom address contents 0 0xb2 1 vendor id (vid) l 2 vendor id (vid) h 3 product id (pid) l 4 product id (pid) h 5 device id (did) l 6 device id (did) h 7 length h 8 length l 9 startaddr h 10 startaddr l --- data block --- --- length h --- length l --- startaddr h --- startaddr l --- data block --- --- 0x80 --- 0x01 --- 0x7f --- 0x92 --- last 00000000
ez-usb technical reference manual page 5-10 ez-usb technical reference manual v1.10 one or more data records follow, starting at eeprom address 7. the maximum value of length h is 0x03, allowing a maximum of 1,023 bytes per record. each data record consists of a length, a starting address, and a block of data bytes. the last data record must have the msb of its length h byte set to 1. the last data record consists of a single-byte load to the cpucs register at 0x7f92. only the lsb of this byte is significant?8051res (cpucs.0) is set to zero to bring the 8051 out of reset. serial eeprom data can be loaded into two ez-usb ram spaces only. ? 8051 program/data ram at 0x0000-0x1b40. ? the cpucs register at 0x7f92 (only bit 0, 8051 reset, is host-loadable). 5.9 renumeration ? three ez-usb control bits in the usbcs (usb control and status) register control the renumer- ation ? process: discon, discoe, and renum. figure 5-1. usb control and status register vid/pid/did in a ?b2? eeprom bytes 1-6 of a b2 eeprom can be loaded with vid/pid/did bytes if it is desired at some point to run the 8051 program with renum=0 (ez-usb core handles device requests), using the eeprom vid/pid/did rather than the cypress semiconductor values built into the ez-usb core. usbcs usb control and status 7fd6 b7 b6 b5 b4 b3 b2 b1 b0 wa k e s r c - - - discon discoe renum sigrsume r/w r r r r/w r/w r/w r/w 00000100
chapter 5. ez-usb enumeration and renumeration? page 5-11 figure 5-2. disconnect pin logic the logic for the discon and discoe bits is shown in figure 5-2. to simulate a usb disconnect, the 8051 writes the value 00001010 to usbcs. this floats the discon# pin, and provides an internal discon signal to the usb core that causes it to perform disconnect housekeeping. to re-connect to usb, the 8051 writes the value 00000110 to usbcs. this presents a logic hi to the discon# pin, enables the output buffer, and sets the renum bit hi to indicate that the 8051 (and not the usb core) is now in control for usb transfers. this arrangement allows connecting the 1,500-ohm resistor directly between the discon# pin and the usb d+ line (figure 5-3). figure 5-3. typical disconnect circuit (discoe=1) 5.10 multiple renumerations ? the 8051 can renumerate ? anytime. one use for this capability might be to fine tune an isochro- nous endpoint?s bandwidth requests by trying various descriptor values and renumerating. internal logic discon discoe discon# pin discon# d- d+ ez-usb to 3.3v regulator 1500 j1 usb-b vcc 1 d- 2 d+ 3 gnd 4
ez-usb technical reference manual page 5-12 ez-usb technical reference manual v1.10 5.11 default descriptor tables 5-9 through 5-19 show the descriptor data built into the ez-usb core. the tables are pre- sented in the order that the bytes are stored. the device descriptor specifies a maxpacketsize of 64 bytes for endpoint 0, contains cypress semiconductor vendor, product and release number ids, and uses no string indices. release number ids ( xx and yy ) are found in individual cypress semiconductor data sheets. the ez- usb core returns this information response to a ?get_descriptor/device? host request. table 5-9. usb default device descriptor offset field description value 0 blength length of this descriptor = 18 bytes 12h 1 bdescriptortype descriptor type = device 01h 2 bcdusb (l) usb specification version 1.00 (l) 00h 3 bcdusb (h) usb specification version 1.00 (h) 01h 4 bdeviceclass device class (ff is vendor-specific) ffh 5 bdevicesubclass device sub-class (ff is vendor-specific) ffh 6 bdeviceprotocol device protocol (ff is vendor-specific) ffh 7 bmaxpacketsize0 maximum packet size for ep0 = 64 bytes 40h 8 idvendor (l) vendor id (l) cypress semiconductor = 0547h 47h 9 idvendor (h) vendor id (h) 05h 10 idproduct (l) product id (l) ez-usb = 2131h 31h 11 idproduct (h) product id (h) 21h 12 bcddevice (l) device release number (bcd,l) (see individual data sheet) 21h 13 bcddevice (h) device release number (bcd,h) (see individual data sheet) yyh 14 imanufacturer manufacturer index string = none 00h 15 iproduct product index string = none 00h 16 iserialnumber serial number index string = none 00h 17 bnumconfigurations number of configurations in this interface = 1 01h
chapter 5. ez-usb enumeration and renumeration? page 5-13 the configuration descriptor includes a total length field (offset 2-3) that encompasses all interface and endpoint descriptors that follow the configuration descriptor. this configuration describes a single interface (offset 4). the host selects this configuration by issuing a set_configuration requests specifying configuration #1 (offset 5). interface 0, alternate setting 0 describes endpoint 0 only. this is a zero bandwidth setting. the interface has no string index. table 5-10. usb default configuration descriptor offset field description value 0 blength length of this descriptor = 9 bytes 09h 1 bdescriptortype descriptor type = configuration 02h 2 wtotallength (l) total length (l) including interface and endpoint descriptors dah 3 wtotallength (h) total length (h) 00h 4 bnuminterfaces number of interfaces in this configuration 01h 5 bconfigurationvalue configuration value used by set_configuration request to select this configuration 01h 6 iconfiguration index of string describing this configuration = none 00h 7 bmattributes attributes - bus-powered, no wakeup 80h 8 maxpower maximum power - 100 ma 32h table 5-11. usb default interface 0, alternate setting 0 descriptor offset field description value 0 blength length of the interface descriptor 09h 1 bdescriptortype descriptor type = interface 04h 2 binterfacenumber zero-based index of this interface = 0 00h 3 balternatesetting alternate setting value = 0 00h 4 bnumendpoints number of endpoints in this interface (not counting epo) = 0 00h 5 binterfaceclass interface class = vendor specific ffh 6 binterfacesubclass interface sub-class = vendor specific ffh 7 binterfaceprotocol interface protocol = vendor specific ffh 8 iinterface index to string descriptor for this interface = none 00h
ez-usb technical reference manual page 5-14 ez-usb technical reference manual v1.10 interface 0, alternate setting 1 has thirteen endpoints, whose individual descriptors follow the inter- face descriptor. the alternate settings have no string indices. interface 0, alternate setting 1 has one interrupt endpoint, in1, which has a maximum packet size of 16 and a polling interval of 10 ms. table 5-12. usb default interface 0, alternate setting 1 descriptor offset field description value 0 blength length of the interface descriptor 09h 1 bdescriptortype descriptor type = interface 04h 2 binterfacenumber zero-based index of this interface = 0 00h 3 balternatesetting alternate setting value = 1 01h 4 bnumendpoints number of endpoints in this interface (not counting epo) = 13 0dh 5 binterfaceclass interface class = vendor specific ffh 6 binterfacesubclass interface sub-class = vendor specific ffh 7 binterfaceprotocol interface protocol = vendor specific ffh 8 iinterface index to string descriptor for this interface = none 00h table 5-13. usb default interface 0, alternate setting 1, interrupt endpoint descriptor offset field description value 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = in1 81h 3 bmattributes xfr type = int 03h 4 wmaxpacketsize (l) maximum packet size = 16 bytes 10h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds = 10 ms 0ah
chapter 5. ez-usb enumeration and renumeration? page 5-15 table 5-14. usb default interface 0, alternate setting 1, bulk endpoint descriptors offset field description value 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = in2 82h 3 bmattributes xfr type = bulk 02h 4 wmaxpacketsize (l) maximum packet size = 64 bytes 40h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 00h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = out2 02h 3 bmattributes xfr type = bulk 02h 4 wmaxpacketsize (l) maximum packet size = 64 bytes 40h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 00h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = in4 84h 3 bmattributes xfr type = bulk 02h 4 wmaxpacketsize (l) maximum packet size = 64 bytes 40h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 00h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = out4 04h 3 bmattributes xfr type = bulk 02h 4 wmaxpacketsize (l) maximum packet size = 64 bytes 40h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 00h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = in6 86h 3 bmattributes xfr type = bulk 02h 4 wmaxpacketsize (l) maximum packet size = 64 bytes 40h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 00h
ez-usb technical reference manual page 5-16 ez-usb technical reference manual v1.10 interface 0, alternate setting 1 has six bulk endpoints with max packet sizes of 64 bytes. even numbered endpoints were chosen to allow endpoint pairing. for more on endpoint pairing, see chapter 6, "ez-usb bulk transfers." 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = out6 06h 3 bmattributes xfr type = bulk 02h 4 wmaxpacketsize (l) maximum packet size = 64 bytes 40h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 00h table 5-14. usb default interface 0, alternate setting 1, bulk endpoint descriptors (continued) offset field description value
chapter 5. ez-usb enumeration and renumeration? page 5-17 table 5-15. usb default interface 0, alternate setting 1, isochronous endpoint descriptors offset field description value 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = in8 88h 3 bmattributes xfr type = iso 01h 4 wmaxpacketsize (l) maximum packet size = 16 bytes 10h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 01h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = out8 08h 3 bmattributes xfr type = iso 01h 4 wmaxpacketsize (l) maximum packet size = 16 bytes 10h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 01h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = in9 89h 3 bmattributes xfr type = iso 01h 4 wmaxpacketsize (l) maximum packet size = 16 bytes 10h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 01h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = out9 09h 3 bmattributes xfr type = iso 01h 4 wmaxpacketsize (l) maximum packet size = 16 bytes 10h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 01h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = in10 8ah 3 bmattributes xfr type = iso 01h 4 wmaxpacketsize (l) maximum packet size = 16 bytes 10h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 01h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = out10 0ah 3 bmattributes xfr type = iso 01h 4 wmaxpacketsize (l) maximum packet size = 16 bytes 10h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 01h
ez-usb technical reference manual page 5-18 ez-usb technical reference manual v1.10 interface 0, alternate setting 1 has six isochronous endpoints with maximum packet sizes of 16 bytes. this is a low bandwidth setting. interface 0, alternate setting 2 has thirteen endpoints, whose individual descriptors follow the inter- face descriptor. alternate setting 2 differs from alternate setting 1 in the maximum packet sizes of its interrupt endpoint and two of its isochronous endpoints (ep8in and ep8out). alternate setting 2 for the interrupt 1-in increases the maximum packet size for the interrupt end- point to 64. table 5-16. usb default interface 0, alternate setting 2 descriptor offset field description value 0 blength length of the interface descriptor 09h 1 bdescriptor type descriptor type = interface 04h 2 binterfacenumber zero-based index of this interface = 0 00h 3 balternatesetting alternate setting value = 2 02h 4 bnumendpoints number of endpoints in this interface (not counting epo) = 13 0dh 5 binterfaceclass interface class = vendor specific ffh 6 binterfacesubclass interface sub-class = vendor specific ffh 7 binterfaceprotocol interface protocol = vendor specific ffh 8 iinterface index to string descriptor for this interface = none 00h table 5-17. usb default interface 0, alternate setting 1, interrupt endpoint descriptor offset field description value 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = in1 81h 3 bmattributes xfr type = int 03h 4 wmaxpacketsize (l) maximum packet size = 64 bytes 40h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds = 10 ms 0ah
chapter 5. ez-usb enumeration and renumeration? page 5-19 the bulk endpoints for alternate setting 2 are identical to alternate setting 1. table 5-18. usb default interface 0, alternate setting 2, bulk endpoint descriptors offset field description value 0 blength length of this endpoint descriptor 07h 1 bdescriptor type descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = in2 82h 3 bmattributes xfr type = bulk 02h 4 wmaxpacketsize (l) maximum packet size = 64 bytes 40h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 00h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = out2 02h 3 bmattributes xfr type = bulk 02h 4 wmaxpacketsize (l) maximum packet size = 64 bytes 40h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 00h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = in4 84h 3 bmattributes xfr type = bulk 02h 4 wmaxpacketsize (l) maximum packet size = 64 bytes 40h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 00h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = out4 04h 3 bmattributes xfr type = iso 02h 4 wmaxpacketsize (l) maximum packet size = 64 bytes 40h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 00h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = in6 86h 3 bmattributes xfr type = bulk 02h 4 wmaxpacketsize (l) maximum packet size = 64 bytes 40h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 00h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = out6 06h 3 bmattributes xfr type = bulk 02h 4 wmaxpacketsize (l) maximum packet size = 64 bytes 40h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 00h
ez-usb technical reference manual page 5-20 ez-usb technical reference manual v1.10 the only differences between alternate settings 1 and 2 are the maximum packet sizes for ep8in and ep8out. this is a high-bandwidth setting using 256 bytes each. table 5-19. usb default interface 0, alternate setting 2, isochronous endpoint descriptors offset field description value 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = in8 88h 3 bmattributes xfr type = iso 01h 4 wmaxpacketsize (l) maximum packet size = 256 bytes 10h 5 wmaxpacketsize (h) maximum packet size - high 01h 6 binterval polling interval in milliseconds (1 for iso) 01h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = out8 08h 3 bmattributes xfr type = iso 01h 4 wmaxpacketsize (l) maximum packet size = 256 bytes 00h 5 wmaxpacketsize (h) maximum packet size - high 10h 6 binterval polling interval in milliseconds (1 for iso) 01h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = in9 89h 3 bmattributes xfr type = iso 01h 4 wmaxpacketsize (l) maximum packet size = 16 bytes 10h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 01h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = out9 09h 3 bmattributes xfr type = iso 01h 4 wmaxpacketsize (l) maximum packet size = 16 bytes 10h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 01h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = in10 8ah 3 bmattributes xfr type = iso 01h 4 wmaxpacketsize (l) maximum packet size = 16 bytes 10h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 01h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = out10 0ah 3 bmattributes xfr type = iso 01h 4 wmaxpacketsize (l) maximum packet size = 16 bytes 10h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 01h
chapter 6. ez-usb bulk transfers page 6-1 chapter 6 ez-usb bulk transfers 6.1 introduction figure 6-1. two bulk transfers, in and out ez-usb provides sixteen endpoints for bulk, control, and interrupt transfers, numbered 0-7 as shown in table 6-1. this chapter describes bulk and interrupt transfers. inter- rupt transfers are a special case of bulk transfers. ez-usb control endpoint zero is described in chapter 7, "ez-usb endpoint zero." table 6-1. ez-usb bulk, control, and interrupt endpoints endpoint direction type size 0 bidir control 64/64 1 in bulk/int 64 1 out bulk/int 64 2 in bulk/int 64 2 out bulk/int 64 3 in bulk/int 64 3 out bulk/int 64 4 in bulk/int 64 4 out bulk/int 64 5 in bulk/int 64 5 out bulk/int 64 6 in bulk/int 64 6 out bulk/int 64 7 in bulk/int 64 7 out bulk/int 64 i n a d d r e n d p c r c 5 token packet payload data c r c 1 6 data packet a c k i n a d d r e n d p c r c 5 token packet d a t a 0 payload data c r c 1 6 data packet a c k h/s pkt h/s pkt d a t a 1
ez-usb technical reference manual page 6-2 ez-usb technical reference manual v1.10 the usb specification allows maximum packet sizes of 8, 16, 32, or 64 bytes for bulk data, and 1 - 64 bytes for interrupt data. ez-usb provides the maximum 64 bytes of buffer space for each of its sixteen endpoints 0-7 in and 0-7 out. six of the bulk endpoints, 2-in, 4-in, 6-in, 2-out, 4- out, and 6-out may be paired with the next consecutively numbered endpoint to provide double- buffering, which allows one data packet to be serviced by the 8051 while another is in transit over usb. six endpoint pairing bits (usbpair register) control double-buffering. the 8051 sets fourteen endpoint valid bits (in07val, out07val registers) at initialization time to tell the ez-usb core which endpoints are active. the default control endpoint zero is always valid. bulk data appears in ram. each bulk endpoint has a reserved 64-byte ram space, a 7-bit count register, and a 2-bit control and status (cs) register. the 8051 can read one bit of the cs register to determine endpoint busy , and write the other to force an endpoint stall condition. the 8051 should never read or write an endpoint buffer or byte count register while the endpoint?s busy bit is set. when an endpoint becomes ready for 8051 service, the ez-usb core sets an interrupt request bit. the ez-usb vectored interrupt system separates the interrupt requests by endpoint to automati- cally transfer control to the isr (interrupt service routine) for the endpoint requiring service. chapter 9, "ez-usb interrupts" fully describes this mechanism. figure 6-2 illustrates the registers and bits associated with bulk transfers.
chapter 6. ez-usb bulk transfers page 6-3 figure 6-2. registers associated with bulk endpoints 64 byte endpoint buffer 5 in07val usbpair endpoint valid (1=valid) endpoint pairing (1=paired) byte count control & status s b in07irq interrupt request (write 1 to clear) in07ien interrupt enable (1=enabled) in2bc 7 6 4 3 2 1 0 5 7 6 4 3 2 1 0 i23 i45 i67 o23 o45 o67 5 7 6 4 3 2 1 0 initialization in2buf data transfer in2cs interrupt control busy and stall registers associated with a bulk in endpoint (ep2in shown as example) 64 byte endpoint buffer 5 out07val usbpair byte count control & status s b out07irq out07ien out4bc 7 6 4 3 2 1 0 5 7 6 4 3 2 1 0 i23 i45 i67 o23 o45 o67 5 7 6 4 3 2 1 0 out4buf data transfer out4cs interrupt control busy and stall registers associated with a bulk out endpoint (ep4out shown as example) initialization endpoint valid (1=valid) endpoint pairing (1=paired) interrupt enable (1=enabled) interrupt request (write 1 to clear)
ez-usb technical reference manual page 6-4 ez-usb technical reference manual v1.10 6.2 bulk in transfers figure 6-3. anatomy of a bulk in transfer usb bulk in data travels from device to host. the host requests an in transfer by issuing an in token to the ez-usb core, which responds with data when it is ready. the 8051 indicates ready by loading the endpoint?s byte count register. if the ez-usb core receives an in token for an end- point that is not ready, it responds to the in token with a nak handshake. in the bulk in transfer illustrated in figure 6-3, the 8051 has previously loaded an endpoint buffer with a data packet, and then loaded the endpoint?s byte count register with the number of bytes in the packet to arm the next in transfer. this sets the endpoint?s busy bit. the host issues an in token (1), to which the usb core responds by transmitting the data in the in endpoint buffer (2). when the host issues an ack (3), indicating that the data has been received error-free, the usb core clears the endpoint?s busy bit and sets its interrupt request bit. this notifies the 8051 that the endpoint buffer is empty. if this is a multi-packet transfer, the host then issues another in token to get the next packet. if the second in token (4) arrives before the 8051 has had time to fill the endpoint buffer, the ez usb core issues a nak handshake, indicating busy (5). the host continues to send in tokens (4) and (7) until the data is ready. eventually, the 8051 fills the endpoint buffer with data, and then loads the endpoint?s byte count register (innbc) with the number of bytes in the packet (6). load- i n a d d r e n d p c r c 5 token packet d a t a 1 payload data c r c 1 6 data packet a c k i n a d d r e n d p c r c 5 token packet h/s pkt epnin interrupt, innbsy=0 n a k (innbc loaded) .. . h d hd h 1 2 3 4 5 i n a d d r e n d p c r c 5 token packet n a k i n a d d r e n d p c r c 5 token packet d a t a 0 payload data c r c 1 6 data packet a c k h/s pkt ... load innbc epnin interrupt, innbsy=0 h dhd h 4 5 6 8 7 ... h/s pkt n o t e: h = h o s t , d = d e v i ce ( ez - u s b ) ... h/s pkt
chapter 6. ez-usb bulk transfers page 6-5 ing the byte count re-arms the given endpoint. when the next in token arrives (7) the usb core transfers the next data packet (8). 6.3 interrupt transfers interrupt transfers are handled just like bulk transfers. the only difference between a bulk endpoint and an interrupt endpoint exists in the endpoint descriptor, where the endpoint is identified as type interrupt , and a polling interval is specified. the polling interval determines how often the usb host issues in tokens to the interrupt endpoint. 6.4 ez-usb bulk in example suppose 220 bytes are to be transferred to the host using endpoint 2-in. further assume that maxpacketsize of 64 bytes for endpoint 2-in has been reported to the host during enumeration. because the total transfer size exceeds the maximum packet size, the 8051 divides the 220-byte transfer into four transfers of 64, 64, 64, and 28 bytes. after loading the first 64 bytes into in2buf (at 0x7c00), the 8051 loads the byte count register in6bc with the value 64. writing the byte count register instructs the ez-usb core to respond to the next host in token by transmitting the 64 bytes in the buffer. until the byte count register is loaded to arm the in transfer, any in tokens issued by the host are answered by ez-usb with nak (not-acknowledge) tokens, telling the usb host that the endpoint is not yet ready with data. the host continues to issue in tokens to endpoint 2-in until data is ready for transfer?whereupon the ez-usb core replaces naks with valid data. when the 8051 initiates an in transfer by loading the endpoint?s byte count register, the ez-usb core sets a busy bit to instruct the 8051 to hold off loading in2buf until the usb transfer is fin- ished. when the in transfer is complete and successfully acknowledged, the ez-usb core resets the endpoint 2-in busy bit and generates an endpoint 2-in interrupt request. if the endpoint 2-in interrupt is enabled, program control automatically vectors to the data transfer routine for further action (autovectoring is enabled by setting aven=1; refer to chapter 9, "ez-usb interrupts"). the 8051 now loads the next 64 bytes into in2buf and then loads the epinbc register with 64 for the next two transfers. for the last portion of the transfer, the 8051 loads the final 28 bytes into in2buf, and loads in2bc with 28. this completes the transfer.
ez-usb technical reference manual page 6-6 ez-usb technical reference manual v1.10 the ez-usb core takes care of usb housekeeping chores such as handshake verification. when an endpoint 2-in interrupt occurs, the user is assured that the data loaded by the 8051 into the endpoint buffer was received error-free by the host. the ez-usb core automatically checks the handshake information from the host and re-transmits the data if the host indicates an error by not acking. 6.5 bulk out transfers usb bulk out data travels from host to device. the host requests an out transfer by issuing an out token to ez-usb, followed by a packet of data. the ez-usb core then responds with an ack, if it correctly received the data. if the endpoint buffer is not ready to accept data, the ez- usb core discards the host?s out data and returns a nak token, indicating ?not ready.? in response, the host continues to send out tokens and data to the endpoint until the ez-usb core responds with an ack. initialization note when the ez-usb chip comes out of reset, or when the usb host issues a bus reset, the ez- usb core unarms in endpoint 1-7 by setting their busy bits to 0. any in transfer requests are nakd until the 8051 loads the appropriate inxbc register(s). the endpoint valid bits are not affected by an 8051 reset or a usb reset. chapter 10, "ez-usb resets" describes the various reset conditions in detail.
chapter 6. ez-usb bulk transfers page 6-7 figure 6-4. anatomy of a bulk out transfer each ez-usb bulk out endpoint has a byte count register, which serves two purposes. the 8051 reads the byte count register to determine how many bytes were received during the last out transfer from the host. the 8051 writes the byte count register (with any value) to tell the ez-usb core that is has finished reading bytes from the buffer, making the buffer available to accept the next out transfer. the out endpoints come up (after reset) armed , so the byte count register writes are required only for out transfers after the first one. in the bulk out transfer illustrated in figure 6-4, the 8051 has previously loaded the endpoint?s byte count register with any value to arm receipt of the next out transfer. loading the byte count register causes the ez-usb core to set the out endpoint?s busy bit to 1, indicating that the 8051 should not use the endpoint?s buffer. the host issues an out token (1), followed by a packet of data (2), which the usb core acknowl- edges, clears the endpoint?s busy bit and generates an interrupt request (3). this notifies the 8051 that the endpoint buffer contains valid usb data. the 8051 reads the endpoint?s byte count register to find out how many bytes were sent in the packet, and transfers that many bytes out of the end- point buffer. in a multi-packet transfer, the host then issues another out token (4) along with the next data packet (5). if the 8051 has not finished emptying the endpoint buffer, the ez-usb fx host issues a nak, indicating busy (6). the data at (5) is shaded to indicate that the usb core discards it, and does not over-write the data in the endpoint?s out buffer. o u t a d d r e n d p c r c 5 token packet d a t a 1 payload data c r c 1 6 data packet a c k o u t a d d r e n d p c r c 5 token packet h/s pkt epnout interrupt, outnbsy=0 n a k .. . dd h h 1 2 3 4 6 o u t a d d r e n d p c r c 5 token packet d a t a 0 payload data c r c 1 6 data packet a c k h/s pkt load outnbc (any value), causes outnbsy=1 epnout interrupt, outnbsy=0 d hh 7 9 8 h/s pkt h d a t a 0 payload data c r c 1 6 data packet 5 h o u t a d d r e n d p c r c 5 token packet n a k .. . d h 4 6 h/s pkt d a t a 0 payload data c r c 1 6 data packet 5 h (outnbc loaded, outnbsy=1) ... n o t e: h = h o s t , d = d e v i ce ( ez - u s b )
ez-usb technical reference manual page 6-8 ez-usb technical reference manual v1.10 the host continues to send out tokens (4, 5, and 6) that are greeted by naks until the buffer is ready. eventually, the 8051 empties the endpoint buffer data, and then loads the endpoint?s byte count register (7) with any value to re-arm the usb core. once armed and when the next out token arrives (8) the usb core accepts the next data packet (9). the ez-usb core takes care of usb housekeeping chores such as crc checks and data toggle pids. when an endpoint 6-out interrupt occurs and the busy bit is cleared, the user is assured that the data in the endpoint buffer was received error-free from the host. the ez-usb core auto- matically checks for errors and requests the host to re-transmit data if it detects any errors using the built-in usb error checking mechanisms (crc checks and data toggles). 6.6 endpoint pairing the 8051 sets endpoint pairing bits to 1 to enable double-buffering of the bulk endpoint buffers. with double buffering enabled, the 8051 can operate on one data packet while another is being transferred over usb. the endpoint busy and interrupt request bits function identically, so the 8051 code requires little code modification to support double-buffering. when an endpoint is paired, the 8051 uses only the even-numbered endpoint of the pair. the 8051 should not use the paired odd endpoint. for example, suppose it is desired to use endpoint 2-in as a double-buffered endpoint. this pairs the in2buf and in3buf buffers, although the 8051 accesses the in2buf buffer only. the 8051 sets pr2in=1 (in the usbpair register) to enable pairing, sets in2val=1 (in the in07val register) to make the endpoint valid, and then uses the in2buf buffer for all data transfers. the 8051 should not write the in3val bit, enable in3 interrupts, access the ep3in buffer, or load the in3bc byte count register. initializing out endpoints when the ez-usb chip comes out of reset, or when the usb host issues a bus reset, the ez- usb core arms out endpoints 1-7 by setting their busy bits to 1. therefore, they are initially ready to accept one out transfer from the host. subsequent out transfers are nakd until the appropriate outnbc register is loaded to re-arm the endpoint. table 6-2. endpoint pairing bits (in the usb pair register) bit 543210 name pr6out pr4out pr2out pr6in pr4in pr2in paired 6 out 4 out 2 out 6 in 4 in 2 in endpoints 7 out 5 out 3 out 7 in 5 in 3 in
chapter 6. ez-usb bulk transfers page 6-9 6.7 paired in endpoint status innbsy=1 indicates that both endpoint buffers are in use, and the 8051 should not load new in data into the endpoint buffer. when innbsy=0, either one or both of the buffers is available for loading by the 8051. the 8051 can keep an internal count that increments on epnin interrupts and decrements on byte count loads to determine whether one or two buffers are free. or, the 8051 can simply check for innbsy=0 after loading a buffer (and loading its byte count register to re-arm the endpoint) to determine if the other buffer is free. a bulk in endpoint interrupt request is generated whenever a packet is successfully transmitted over usb. the interrupt request is independent of the busy bit. if both buffers are filled and one is sent, the busy bit transitions from 1-0; if one buffer is filled and then sent, the busy bit starts and remains at 0. in either case an interrupt request is generated to tell the 8051 that a buffer is free. 6.8 paired out endpoint status outnbsy=1 indicates that both endpoint buffers are empty, and no data is available to the 8051. when outnbsy=0, either one or both of the buffers holds usb out data. the 8051 can keep an internal count that increments on epnout interrupts and decrements on byte count loads to deter- mine whether one or two buffers contain data. or, the 8051 can simply check for outnbsy=0 after unloading a buffer (and loading its byte count register to re-arm the endpoint) to determine if the other buffer contains data. important note if an in endpoint is paired and it is desired to clear the busy bit for that endpoint, do the following: (a) write any value to the even endpoint?s byte count register twice , and (b) clear the busy bit for both endpoints in the pair. this is the only code difference between paired and unpaired use of an in endpoint.
ez-usb technical reference manual page 6-10 ez-usb technical reference manual v1.10 6.9 using bulk buffer memory table 6-3 shows the ram locations for the sixteen 64-byte buffers for endpoints 0-7 in and out. these buffers are positioned at the bottom of the ez-usb register space so that any buffers not used for endpoints can be reclaimed as general purpose data ram. the top of memory for the 8- kb ez-usb part is at 0x1b3f. however, if the endpoints are allocated in ascending order starting with the lowest numbered endpoints, the higher numbered unused endpoints can effectively move the top of memory to utilize the unused endpoint buffer ram as data memory. for example, an application that uses endpoint 1-in, 2-in/out (paired), 4-in and 4-out can use 0x1b40-0x1cbf as data memory. chapter 3 gives full details of the ez-usb memory map. table 6-3. ez-usb endpoint 0-7 buffer addresses endpoint buffer address mirrored in0buf 7f00-7f3f 1f00-1f3f out0buf 7ec0-7eff 1ec0-1eff in1buf 7e80-7ebf 1e80-1ebf out1buf 7e40-7e7f 1e40-1e7f in2buf 7e00-7e3f 1e00-1e3f out2buf 7dc0-7dff 1dc0-1dff in3buf 7d80-7dbf 1d80-1dbf out3buf 7d40-7d7f 1d40-1d7f in4buf 7d00-7d3f 1d00-1d3f out4buf 7cc0-7cff 1cc0-1cff in5buf 7c80-7cbf 1c80-1cbf out5buf 7c40-7c7f 1c40-1c7f in6buf 7c00-7c3f 1c00-1c3f out6buf 7bc0-7bff 1bc0-1bff in7buf 7b80-7bbf 1b80-1bbf out7buf 7b40-7b7f 1b40-1b7f note uploads or downloads to unused bulk memory can be done only at the mirrored (low) addresses shown in table 6-3.
chapter 6. ez-usb bulk transfers page 6-11 6.10 data toggle control the ez-usb core automatically maintains the data toggle bits during bulk, control and interrupt transfers. as explained in chapter 1, "introducing ez-usb," the toggle bits are used to detect cer- tain transmission errors so that erroneous data can be re-sent. in certain circumstances, the host resets its data toggle to ?data0?: ? after sending a clear_feature: endpoint stall request to an endpoint. ? after setting a new interface. ? after selecting a new alternate setting. in these cases, the 8051 can directly clear the data toggle for each of the bulk/interrupt/control endpoints, using the togctl register (figure 6-5). figure 6-5. bulk endpoint toggle control the io bit selects the endpoint direction (1=in, 0=out), and the ep2-ep1-ep0 bits select the end- point number. the q bit, which is read-only, indicates the state of the data toggle for the selected endpoint. writing r=1 sets the data toggle to data0, and writing s=1 sets the data toggle to data1. to clear an endpoint?s data toggle, the 8051 performs the following sequence: ? select the endpoint by writing the value 000d0eee to the togctl register, where d is the direction and eee is the endpoint number. ? clear the toggle bit by writing the value 001d0eee to the togctl register. after step 1, the 8051 may read the state of the data toggle by reading the togctl register checking bit 7. togctl data toggle control 7fd7 b7 b6 b5 b4 b3 b2 b1 b0 q s r io 0 ep2 ep1 ep0 r r/w r/w r/w r/w r/w r/w r/w x x x x x x x x note at the present writing, there appears to be no reason to set a data toggle to data1. the s bit is provided for generality.
ez-usb technical reference manual page 6-12 ez-usb technical reference manual v1.10 6.11 polled bulk transfer example the following code illustrates the ez-usb registers used for a simple bulk transfer. in this exam- ple, 8051 register r1 keeps track of the number of endpoint 2-in transfers and register r2 keeps track of the number of endpoint 2-out transfers (mod-256). every endpoint 2-in transfer consists of 64 bytes of a decrementing count, with the first byte replaced by the number of in transfers and the second byte replaced by the number of out transfers. figure 6-6. example code for a simple (polled) bulk transfer 1 start: mov sp,#stack-1 ; set stack 2 mov dptr,#in2buf ; fill ep2in buffer with 3 mov r7,#64 ; decrementing counter 4 fill: mov a,r7 5 movx @dptr,a 6 inc dptr 7 djnz r7,rill 8; 9 mov r1,#0 ; r1 is in token counter 10 mov r2,#0 ; r2 is out token counter 11 mov dptr,#in2bc ; point to ep2 byte count register 12 mov a,#40h ; 64-byte transfer 13 movx @dptr,a ; arm the in2 transfer 14 ; 15 loop: mov dptr,#in2cs ; poll the ep2-in status 16 movx a,@dptr 17 jnb acc.1,servicein2 ; not busy--keep looping 18 mov dptr,#out2cs 19 movx a,@dptr 20 jb acc.1,loop ; ep2out is busy--keep looping 21 ; 22 serviceout2: 23 inc r2 ; out packet counter 24 mov dptr,#out2bc ; load byte count register to re-arm 25 movx @dptr,a ; (any value) 26 sjmp loop 27 ; 28 servicein2: 29 inc r1 ; in packet counter 30 mov dptr,3in2buf ; update the first data byte 31 mov a,r1 ; in ep2in buffer 32 movx @dptr,a 33 inc dptr ; second byte in buffer 34 mov a,r2 ; get number of out packets 35 movx @dptr,a 36 mov dptr,#in2bc ; point to ep2in byte count register 37 mov a,#40h 38 movx @dptr,a ; load bc=64 to re-arm in2 39 sjmp loop 40 ; 41 end
chapter 6. ez-usb bulk transfers page 6-13 the code at lines 2-7 fills the endpoint 2-in buffer with 64 bytes of a decrementing count. two 8- bit counts are initialized to zero at lines 9 and 10. an endpoint 2-in transfer is armed at lines 11- 13, which load the endpoint 2-in byte count register in2bc with 64. then the program enters a polling loop at lines 15-20, where it checks two flags for endpoint 2 servicing. lines 15-17 check the endpoint 2-in busy bit in in2cs bit 1. lines 18-20 check the endpoint 2-out busy bit in out2cs bit 1. when busy=1, the ez-usb core is currently using the endpoint buffers and the 8051 should not access them. when busy=0, new data is ready for service by the 8051. for both in and out endpoints, the busy bit is set when the ez-usb core is using the buffers, and cleared by loading the endpoint?s byte count register. the byte count value is meaningful for in transfers because it tells the ez-usb core how many bytes to transfer in response to the next in token. the 8051 can load any byte count out transfers, because only the act of loading the reg- ister is significant?loading outnbc arms the out transfer and sets the endpoint?s busy bit. when an out packet arrives in out2buf, the service routine at lines 22-26 increments r2, loads the byte count (any value) into out2bc to re-arm the endpoint (lines 24-25), and jumps back to the polling routine. this program does not use out2buf data; it simply counts the number of endpoint 2-out transfers. when endpoint 2-in is ready for the 8051 to load another packet into in2buf, the polling loop jumps to the endpoint 2-in service routine at lines 28-39. first, r1 is incremented (line 29). the data pointer is set to in2buf at line 30, and register r1 is loaded into the first byte of the buffer (lines 31-32). the data pointer is advanced to the second byte of in2buf at line 33, and register r2 is loaded into the buffer (lines 34-35). finally, the byte count 40h (64 decimal bytes) is loaded into the byte count register in2bc to arm the next in transfer at lines 36-38, and the routine returns the polling loop. 6.12 enumeration note the code in this example is complete, and runs on the ez-usb chip. you may be wondering about the missing step , which reports the endpoint characteristics to the host during the enumeration process. the reason this code runs without any enumeration code is that the ez-usb chip comes on as a fully-functional usb device with certain endpoints already configured and reported to the host. endpoint 2 is included in this default configuration. the full default configuration is described in chapter 5, "ez-usb enumeration and renumeration?." 6.13 bulk endpoint interrupts all usb interrupts activate the 8051 int 2 interrupt. if enabled, int2 interrupts cause the 8051 to push the current program counter onto the stack, and then execute a jump to location 0x43, where the programmer has inserted a jump instruction to the interrupt service routine (isr). if the aven (autovector enable) bit is set, the ez-usb core inserts a special byte at location 0x45, which directs the jump instruction to a table of jump instructions which transfer control the endpoint-spe- cific isr.
ez-usb technical reference manual page 6-14 ez-usb technical reference manual v1.10 * replaced by ez-usb core if aven=1. the byte inserted by the ez-usb core at address 0x45 depends on which bulk endpoint requires service. table 6-5 shows all int2 vectors, with the bulk endpoint vectors un-shaded. the shaded interrupts apply to all the bulk endpoints. the vector values are four bytes apart. this allows the programmer to build a jump table to each of the interrupt service routines. note that the jump table must begin on a page (256 byte) bound- ary because the first vector starts at 00. if autovectoring is not used (aven=0), the ivec register may be directly inspected to determine the usb interrupt source (see section 9.11, "autovector coding"). each bulk endpoint interrupt has an associated interrupt enable bit (in in07ien and out07ien), and an interrupt request bit (in in07irq and out07irq). the interrupt service routine. irq bits are cleared by writing a ?1.? because all usb registers are accessed using ?movx@dptr? instruc- table 6-4. 8051 int2 interrupt vector location op-code instruction 0x43 02 ljmp 0x44 addrh 0x45 addrl* table 6-5. byte inserted by ez-usb core at location 0x45 if aven=1 interrupt inserted byte at 0x45 sudav 0x00 sof 0x04 sutok 0x08 suspend 0x0c usbres 0x10 reserved 0x14 ep0-in 0x18 ep0-out 0x1c ep1-in 0x20 ep1out 0x24 ep2in 0x28 ep2out 0x2c ep3-in 0x30 ep3-out 0x34 ep4-in 0x38 ep4-out 0x3c ep5-in 0x40 ep5-out 0x44 ep6-in 0x48 ep6-out 0x4c ep7-in 0x50 ep7-out 0x54
chapter 6. ez-usb bulk transfers page 6-15 tions, usb interrupt service routines must save and restore both data pointers, the dps register, and the accumulator before clearing interrupt request bits. 6.14 interrupt bulk transfer example this simple (but fully-functional) example illustrates the bulk transfer mechanism using interrupts. in the example program, bulk endpoint 6 is used to loop data back to the host. data sent by the host over endpoint 2-out is sent back over endpoint 2-in. note any usb isr should clear the 8051 int2 interrupt request bit before clearing any of the ez-usb endpoint irq bits, to avoid losing interrupts. interrupts are discussed in more detail in chapter 9, "ez-usb interrupts." individual interrupt request bits are cleared by writing ?1? to them to simplify code. for example, to clear the endpoint 2-in irq, simply write ?0000100? to in07irq. this will not disturb the other interrupt request bits. do not read the contents of in07irq, logical-or the contents with 01, and write it back . this clears all other pending interrupts because you are writing ?1?s to them.
ez-usb technical reference manual page 6-16 ez-usb technical reference manual v1.10 1. set up the jump table. figure 6-7. interrupt jump table this table contains all of the usb interrupts, even though only the jumps for endpoint 2 are used for the example. it is convenient to include this table in any usb application that uses interrupts. be sure to locate this table on a page boundary (xx00). cseg at 300h ; any page boundary usb_jump_table: ljmp sudav_isr ; setup data available db 0 ; make a 4-byte entry ljmp sof_isr ; sof db 0 ljmp sutok_isr ; setup data loading db 0 ljmp susp_isr ; global suspend db 0 ljmp ures_isr ; usb reset db 0 ljmp spare_isr db 0 ljmp ep0in_isr db 0 ljmp ep0out_isr db 0 ljmp ep1in_isr db 0 ljmp ep1out_isr db 0 ljmp ep2in_isr db 0 ljmp ep2out_isr db 0 ljmp ep3in_isr db 0 ljmp ep3out_isr db 0 ljmp ep4in_isr db 0 ljmp ep4out_isr db 0 ljmp ep5in_isr db 0 ljmp ep5out_isr db 0 ljmp ep6in_isr ; used by this example db 0 ljmp ep6out_isr ; used by this example db 0 ljmp ep7in_isr db 0 ljmp ep7out_isr db 0
chapter 6. ez-usb bulk transfers page 6-17 2. write the int2 interrupt vector. figure 6-8. int2 interrupt vector 3. write the interrupt service routine. put it anywhere in memory and the jump table in step 1 will automatically jump to it. figure 6-9. interrupt service routine (isr) for endpoint 2-out in this example, the isr simply sets the 8051 flag ?got_ep2_data? to indicate to the background program that the endpoint requires service. note that both data pointers and the dps (data pointer select) registers must be saved and restored in addition to the accumulator. ; ----------------- ; interrupt vectors ; ----------------- org 43h ; int2 is the usb vector ljmp usb_jump_table ; autovector will replace byte 45 ; ----------------------------- ; usb interrupt service routine ; ----------------------------- ep2out_isr push dps ; save both dptrs, dps, and acc push dpl push dph push dpl1 push dph1 push acc mov a,exif ; clear usb irq (int2) clr acc.4 mov exif,a mov dptr,#out07irq mov a,#01000000b ; a ?1? clears the irq bit movx @dptr,a ; clear out2 int request setb got_ep2_data ; set my flag pop acc ; restore vital registers pop dph1 pop dpl1 pop dph pop dpl pop dps reti
ez-usb technical reference manual page 6-18 ez-usb technical reference manual v1.10 4. write the endpoint 2 transfer program. figure 6-10. background program transfers endpoint 2-out data to endpoint 2-in the main program loop tests the ?got_ep2_data? flag, waiting until it is set by the endpoint 2 out interrupt service routine in figure 6-10. this indicates that a new data packet has arrived in out2buf. then the service routine is entered, where the flag is cleared in line 2. the number of bytes received in out2buf is retrieved from the out2bc register (endpoint 2 byte count) and saved in registers r6 and r7 in lines 7-10. the dual data pointers are initialized to the source (out2buf) and destination (in2buf) buffers for the data transfer in lines 15-18. these labels represent the start of the 64-byte buffers for end- point 2-out and endpoint 2-in, respectively. each byte is read from the out2buf buffer and written to the in2buf buffer in lines 19-25. the saved value of out2bc is used as a loop counter in r7 to transfer the exact number of bytes that were received over endpoint 2-out. 1 loop: jnb got_ep2_data,loop 2 clr got_ep2_data ; clear my flag 3; 4 ; the user sent bytes to out2 endpoint using the usb control panel. 5 ; find out how many bytes were sent. 6; 7 mov dptr,#out2bc ; point to out2 byte count register 8 movx a,@dptr ; get the value 9 mov r7,a ; stash the byte count 10 mov r6,a ; save here also 11 ; 12 ; transfer the bytes received on the out2 endpoint to the in2 endpoint 13 ; buffer. number of bytes in r6 and r7. 14 ; 15 mov dptr,#out2buf ; first data pointer points to ep2out buffer 16 inc dps ; select the second data pointer 17 mov dptr,#in2buf ; second data pointer points to ep2in buffer 18 inc dps ; back to first data pointer 19 transfer: movx movx get out byte 20 inc dptr ; bump the pointer 21 inc dps ; second data pointer 22 movx @dptr,a ; put into in buffer 23 inc dptr ; bump the pointer 24 inc dps ; first data pointer 25 djnz r7,transfer 26 ; 27 ; load the byte count into in2bc. this arms in in transfer 28 ; 29 mov dptr,#in2bc 30 mov a,r6 ; get other saved copy of byte count 31 movx @dptr,a ; this arms the in transfer 32 ; 33 ; load any byte count into out2bc. this arms the next out transfer. 34 ; 35 mov dptr,#out2bc 36 movx @dptr,a ; use whatever is in acc 37 sjmp loop ; start checking for another out2 packet
chapter 6. ez-usb bulk transfers page 6-19 when the transfer is complete, the program loads the endpoint 2-in byte count register in2bc with the number of loaded bytes (from r6) to arm the next endpoint 2-in transfer in lines 29-31. finally, the 8051 loads any value into the endpoint 2 out byte count register out2bc to arm the next out transfer in lines 35-36. then the program loops back to check for more endpoint 2-out data. 5. initialize the endpoints and enable the interrupts. figure 6-11. initialization routine the initialization routine sets the stack pointer, and enables the ez-usb autovector by setting usbbav.0 to 1. then it enables the endpoint 2-out interrupt, all usb interrupts (int2), and the 8051 global interrupt (ea) and finally clears the flag indicating that endpoint 2-out requires ser- vice. once this structure is put into place, it is quite easy to service any or all of the bulk endpoints. to add service for endpoint 2-in, for example, simply write an endpoint 2-in interrupt service routine with starting address ep2in_isr (to match the address in the jump table in step 1), and add its valid and interrupt enable bits to the ?init? routine. 6.15 enumeration note the code in this example is complete, and runs on the ez-usb chip. you may be wondering about the missing step , which reports the endpoint characteristics to the host during the enumeration process. the reason this code runs without any enumeration code is that the ez-usb chip comes on as a fully-functional usb device with certain endpoints already configured and reported to the host. endpoint 2 is included in this default configuration. the full default configuration is described in chapter 5, "ez-usb enumeration and renumeration?." start: mov sp,#stack-1 ; set stack ; ; enable usb interrupts and autovector ; mov dptr,#usbbav ; enable autovector movx a,@dptr,a setb acc.0 ; aven bit is bit 0 movx @dptr,a ; mov dptr,#out07ien ; ?ep0-7 out int enables? register ; mov a,#01000000b ; set bit 6 for ep2out interrupt enable movx @dptr,a ; enable ep2out interrupt ; ; enable int2 and 8051 global interrupts ; setb ex2 ; enable int2 (usb interrupt) setb ea ; enable 8051 interrupts clr got_ep2_data ; clear my flag
ez-usb technical reference manual page 6-20 ez-usb technical reference manual v1.10 portions of the above code are not necessary for the default configuration (such as setting the endpoint valid bits) but the code is included to illustrate all of the ez-usb registers used for bulk transfers. 6.16 the autopointer bulk endpoint data is available in 64-byte buffers in ez-usb ram. in some cases it is preferable to access bulk data as a fifo register rather than as a ram. the ez-usb core provides a spe- cial data pointer which automatically increments when data is transferred. using this autopointer, the 8051 can access any contiguous block of internal ez-usb ram as a fifo. figure 6-12. autopointer registers the 8051 first loads autoptrh and autoptrl with a ram address (for example the address of a bulk endpoint buffer). then, as the 8051 reads or writes data to the data register autodata, the address is supplied by autoptrh/l, which automatically increments after every read or write to the autodata register. the autoptrh/l registers may be written or read at anytime. these registers maintain the current pointer address, so the 8051 can read them to determine where the next byte will be read or written. autoptrh autopointer address high 7fe3 b7 b6 b5 b4 b3 b2 b1 b0 a15 a14 a13 a12 a11 a10 a9 a8 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x autoptrl autopointer address low 7fe4 b7 b6 b5 b4 b3 b2 b1 b0 a7 a6 a5 a4 a3 a2 a1 a0 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x autodata autopointer data 7fe5 b7 b6 b5 b4 b3 b2 b1 b0 d7 d6 d5 d4 d3 d2 d1 d0 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x
chapter 6. ez-usb bulk transfers page 6-21 the 8051 code example in figure 6-13 uses the autopointer to transfer a block of eight data bytes from the endpoint 4 out buffer to internal 8051 memory. figure 6-13. use of the autopointer as the comment in the penultimate line indicates, the autopointer saves an ?inc dptr? instruction that would be necessary if one of the 8051 data pointers were used to access the out4buf ram data. this improves the transfer time. as described in chapter 8, "ez-usb isochronous transfers," the ez-usb core provides a method for transferring data directly between an internal fifo and external memory in two 8051 cycles (333 ns). the fast transfer mode is active for bulk data when: ? the 8051 sets fblk=1 in the fastxfr register, enabling fast bulk transfers, ? the 8051 dptr points to the autodata register, and ? the 8051 executes a ?movx a,@dptr? or a ?movx @dptr,a? instruction. the 8051 code example in figure 6-14 shows a transfer loop for moving 64 bytes of external fifo data into the endpoint 4-in buffer. the fastxfr register bits are explained in chapter 8, "ez- usb isochronous transfers." init: mov dptr,#autoptrh mov a,#high(out4buf) ; high portion of out4buf buffer movx @dptr,a ; load outoptrh mov dptr,#autoptrl mov a,#low(out4buf) ; low portion of out4buf buffer address movx @dptr,a ; load autoptrl mov dptr,#autodata ; point to the ?fifo? register mov r0,#80h ; store data in upper 128 bytes of 8051 ram mov r2,#8 ; loop counter ; loop: movx a,@dptr ; get a ?fifo? byte mov @r0,a ; store it inc r0 ; bump destination pointer ; (note: no ?inc dptr? required here) djnz r2,loop ; do it eight times note fastest bulk transfer speed in and out of ez-usb bulk buffers is achieved when the autopointer is used in conjunction with the ez-usb fast transfer mode.
ez-usb technical reference manual page 6-22 ez-usb technical reference manual v1.10 figure 6-14. 8051 code to transfer external data to a bulk in buffer this transfer loop takes 19 cycles per loop times 8 passes, or 22 ms (152 cycles). a usb bulk transfer of 64 bytes takes more that 42 ms (64*8*83 ns) of bus time to transfer the data bytes to or from the host. this calculation neglects usb overhead time. from this simple example, it is clear that by using the autopointer and the ez-usb fast transfer mode, the 8051 can transfer data in and out of ez-usb endpoint buffers significantly faster than the usb can transfer it to and from the host. this means that the ez-usb chip should never be a speed bottleneck in a usb system. it also gives the 8051 ample time for other processing duties between endpoint buffer loads. the autopointer can be used to quickly move data anywhere in ram, not just the bulk endpoint buffers. for example, it can be used to good effect in an application that calls for transferring a block of data into ram, processing the data, and then transferring the data to a bulk endpoint buffer. note the autopointer works only with internal program/data ram. it does not work with memory out- side the chip, or with internal ram that is made available when isodisab=1. see section 8.9.1, "disable iso" for a description of the isodisab bit. mov dptr,#fastxfr ; set up the fast bulk transfer mode mov a,#01000000b ; fblk=1, rpol=0, rm1-0 = 00 movx @dptr,a ; load the fastxfr register init: mov dptr,#autoptrh mov a,#high(in4buf) ; high portion of in4buf movx @dptr,a ; load autoptrh mov dptr,#autoptrl mov a,#low(in4buf) ; low portion of in4buf buffer address movx @dptr,a ; load autoptrh mov dptr,#autodata ; point to the ?fifo? register mov r7,#8 ; r7 is loop counter, 8 bytes per loop ; loop: movx @dptr,a ; (2) write in ?fifo? using byte from external bus movx @dptr,a ; (2) again movx @dptr,a ; (2) again movx @dptr,a ; (2) again movx @dptr,a ; (2) again movx @dptr,a ; (2) again movx @dptr,a ; (2) again movx @dptr,a ; (2) again djnz r7,loop ; (3) do eight more, ?r7? times
chapter 7. ez-usb endpoint zero page 7-1 chapter 7 ez-usb endpoint zero 7.1 introduction endpoint zero has special significance in a usb system. it is a control endpoint, and is required by every usb device. only control endpoints accept special setup tokens that the host uses to signal transfers that deal with device control. the usb host sends a repertoire of standard device requests over endpoint zero. these standard requests are fully defined in chap- ter 9 of the usb specification. this chapter describes how the ez-usb chip handles endpoint zero requests. because the ez-usb chip can enumerate without firmware (see chapter 5, "ez-usb enumeration and renumeration?"), the ez-usb core contains logic to perform enumeration on its own. this hardware assist of endpoint zero operations is make available to the 8051, simplifying the code required to service device requests. this chapter deals with 8051 control of endpoint zero (renum=1, chapter 5), and describes ez-usb resources such as the setup data pointer that sim- plify 8051 code that handles endpoint zero requests. endpoint zero is the only control endpoint in the ez-usb chip. although control endpoints are bi-directional , the ez-usb chip provides two 64-byte buffers, in0buf and out0buf, which the 8051 handles exactly like bulk endpoint buffers for the data stages of a control transfer. a second 8-byte buffer, setupdat, which is unique to endpoint zero, holds data that arrives in the setup stage of a control transfer. this relieves the 8051 programmer of having to keep track of the three control transfer phases?setup, data, and status. the ez-usb core also generates separate interrupt requests for the various transfer phases, further simplifying code. the in0buf and out0buf buffers have two special properties that result from being used by control endpoint zero: ? endpoints 0-in and 0-out are always valid, so the valid bits (lsb of in07val and out07val registers) are permanently set to 1. writing any value to these two bits has no effect, and reading these bits always returns a 1. ? endpoint 0 cannot be paired with endpoint 1, so there is no pairing bit in the usbpair reg- ister for endpoint 0 or 1.
ez-usb technical reference manual page 7-2 ez-usb technical reference manual v1.10 7.2 control endpoint ep0 figure 7-1. a usb control transfer (this one has a data stage) endpoint zero accepts a special setup packet, which contains an 8-byte data structure that pro- vides host information about the control transaction. control transfers include a final sta- tus phase, constructed from standard pids (in/out, data1, and ack/nak). some control transactions include all required data in their 8-byte setup data packet. other control transactions require more out data than will fit into the eight bytes, or require in data from the device. these transactions use standard bulk-like transfers to move the data. note in figure 7-1 that the ?data stage? looks exactly like a bulk transfer. as with bulk endpoints, the endpoint zero byte count registers must be loaded to ack the data transfer stage of a control transfer. 8051 clears hsnak bit (writes 1 to it) or sets the stall bit. i n a d d r e n d p c r c 5 token packet d a t a 0 8 bytes setup data c r c 1 6 data packet a c k h/s pkt s e t u p a d d r e n d p c r c 5 token packet d a t a 1 payload data c r c 1 6 data packet d a t a 1 data pkt a c k i n a d d r e n d p c r c 5 token packet d a t a 0 payload data c r c 1 6 data packet a c k h/s pkt s y n c n a k h/s pkt o u t a d d r e n d p c r c 5 token packet c r c 1 6 setup stage sutok interrupt core sets hsnak=1 sudav interrupt data stage ep0-in interrupt ep0-in interrupt status stage d a t a 1 o u t a d d r e n d p c r c 5 token packet c r c 1 6 .... h/s pkt data pkt a c k h/s pkt
chapter 7. ez-usb endpoint zero page 7-3 the status stage consists of an empty data packet with the opposite direction of the data stage, or an in if there was no data stage. this empty data packet gives the device a chance to ack or nak the entire control transfer. the 8051 writes a ?1? to a bit call hsnak (handshake nak) to clear it and instruct the ez-usb core to ack the status stage. the hsnak bit is used to hold off completing the control transfer until the device has had time to respond to a request. for example, if the host issues a set_interface request, the 8051 per- forms various housekeeping chores such as adjusting internal modes and re-initializing endpoints. during this time the host issues handshake (status stage) packets to which the ez-usb core responds with naks, indicating ?busy.? when the 8051 completes the desired operation, it sets hsnak=1 (by writing a ?1? to the bit) to terminate the control transfer. this handshake pre- vents the host from attempting to use a partially configured interface. to perform an endpoint stall for the data or status stage of an endpoint zero transfer (the setup stage can never stall), the 8051 must set both the stall and hsnak bits for endpoint zero. some control transfers do not have a data stage. therefore the 8051 code that processes the setup data should check the length field in the setup data (in the 8-byte buffer at setup- dat) and arm endpoint zero for the data phase (by loading in0bc or out0bc) only if the length is non-zero. two 8051 interrupts provide notification that a setup packet has arrived, as shown in figure 7-2. figure 7-2. the two interrupts associated with ep0 control transfers the ez-usb core sets the sutokir bit (setup token interrupt request) when the ez-usb core detects the setup token at the beginning of a control transfer. this interrupt is normally used only for debug. the ez-usb core sets the sudavir bit (setup data available interrupt request) when the eight bytes of setup data have been received error-free and transferred to eight ez-usb registers starting at setupdat. the ez-usb core takes care of any re-tries if it finds any errors in the setup data. these two interrupt request bits are set by the ez-usb core, and must be cleared by firmware. d a t a 0 8 bytes setup data c r c 1 6 data packet a c k h/s pkt s e t u p a d d r e n d p c r c 5 token packet setup stage sutok interrupt sudav interrupt 8 ram bytes setupdat
ez-usb technical reference manual page 7-4 ez-usb technical reference manual v1.10 an 8051 program responds to the sudav interrupt request by either directly inspecting the eight bytes at setupdat or by transferring them to a local buffer for further processing. servicing the setup data should be a high 8051 priority, since the usb specification stipulates that control transfers must always be accepted and never nakd. it is therefore possible that a control transfer could arrive while the 8051 is still servicing a previous one. in this case the previous control transfer service should be aborted and the new one serviced. the sutok interrupt gives advance warning that a new control transfer is about to over-write the eight setupdat bytes. if the 8051 stalls endpoint zero (by setting the ep0stall and hsnak bits to 1), the ez-usb core automatically clears this stall bit when the next setup token arrives. like all ez-usb interrupt requests, the sutokir and sudavir bits can be directly tested and reset by the cpu (they are reset by writing a ?1?). thus, if the corresponding interrupt enable bits are zero, the interrupt request conditions can still be directly polled. figure 7-3 shows the ez-usb registers that deal with control transactions over ep0. figure 7-3. registers associated with ep0 control transfers these registers augment those associated with normal bulk transfers over endpoint zero, which are described in chapter 6, "ez-usb bulk transfers." two bits in the usbien (usb interrupt enable) register enable the setup token (sutokie) and setup data interrupts. the actual interrupt request bits are in the usbirq (usb interrupt requests) register. they are called stokir (setup token interrupt request) and sudavir (setup data interrupt request). 8 bytes of setup data usbirq interrupt request: t=setup token sutokir d=setup data sudavir usbien global enable: t=setup token sutokie d=setup data sudavie t initialization setupdat data transfer interrupt control registers associated with endpoint zero for handling setup transactions d t d 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 sudptrh sudptrl
chapter 7. ez-usb endpoint zero page 7-5 the ez-usb core transfers the eight setup bytes into eight bytes of ram at setupdat. a 16- bit pointer, sudptrh/l gives hardware assistance for handling control in transfers, in partic- ular, the usb get_descriptor requests described later in this chapter. 7.3 usb requests the universal serial bus specification version 1.1, chapter 9, "usb device framework" defines a set of standard device requests . when the 8051 is in control (renum=1), the ez-usb core han- dles one of these requests (set address) directly, and relies on the 8051 to support the others. the 8051 acts on device requests by decoding the eight bytes contained in the setup packet. table 7-1 shows the meaning of these eight bytes. the byte column in the previous table shows the byte offset from setupdat. the field column shows the different bytes in the request, where the ?bm? prefix means bit-map, ?b? means byte, and ?w? means word (16 bits). table 7-2 shows the different values defined for brequest, and how the 8051 responds to each request. the remainder of this chapter describes each of the table 7-2 requests in detail. table 7-1. the eight bytes in a usb setup packet byte field meaning 0 bmrequesttype request type, direction, and recipient 1 brequest the actual request (see table 7-2) 2 wvaluel word-size value, varies according to brequest 3wvalueh 4 windexl word-size field, varies according to brequest 5 windexh 6 wlengthl number of bytes to transfer if there is a data phase 7 wlengthh note table 7-2 applies when renum=1, which signifies that the 8051, and not the ez-usb core, han- dles device requests. table 5-2 shows how the core handles each of these device requests when renum=0, for example when the chip is first powered and the 8051 is not running.
ez-usb technical reference manual page 7-6 ez-usb technical reference manual v1.10 in the renumerated condition (renum=1), the ez-usb core passes all usb requests except set address onto the 8051 via the sudav interrupt. this, in conjunction with the usb disconnect/ connect feature, allows a completely new and different usb device (yours) to be characterized by the downloaded firmware. the ez-usb core implements one vendor-specific request, namely ?firmware load,? 0xa0. (the brequest value of 0xa0 is valid only if byte 0 of the request, bmrequesttype, is also ?x10xxxxx,? indicating a vendor-specific request.) the load request is valid at all times, so even after renu- meration the load feature maybe used. if your application implements vendor-specific usb requests, and you do not wish to use the firmware load feature, be sure to refrain from using the brequest value 0xa0 for your custom requests. the firmware load feature is fully described in chapter 5, "ez-usb enumeration and renumeration?." 7.3.1 get status the usb specification version 1.0 defines three usb status requests. a fourth request, to an interface, is indicated in the spec as ?reserved.? the four status requests are: table 7-2. how the 8051 handles usb device requests (renum=1) brequest name action 8051 response 0x00 get status sudav interrupt supply remwu, selfpwr or stall bits 0x01 clear feature sudav interrupt clear remwu, selfpwr or stall bits 0x02 (reserved) none stall ep0 0x03 set feature sudav interrupt set remwu, selfpwr or stall bits 0x04 (reserved) none stall ep0 0x05 set address update fnaddr register none 0x06 get descriptor sudav interrupt supply table data over ep0-in 0x07 set descriptor sudav interrupt application dependent 0x08 get configuration sudav interrupt send current configuration number 0x09 set configuration sudav interrupt change current configuration 0x0a get interface sudav interrupt supply alternate setting no. from ram 0x0b set interface sudav interrupt change alternate setting no. 0x0c sync frame sudav interrupt supply a frame number over ep0-in vendor requests 0xa0 (firmware load) up/download ram --- 0xa1 - 0xaf sudav interrupt reserved by cypress semiconductor all except 0xa0 sudav interrupt depends on application note to avoid future incompatibilities, vendor requests a0-af (hex) are reserved by cypress semi- conductor.
chapter 7. ez-usb endpoint zero page 7-7 ? remote wakeup (device request) ? self-powered (device request) ? stall (endpoint request) ? interface request (?reserved?) the ez-usb core activates the sudav interrupt request to tell the 8051 to decode the setup packet and supply the appropriate status information. figure 7-4. data flow for a get_status request as figure 7-4 illustrates, the 8051 responds to the sudav interrupt by decoding the eight bytes the ez-usb core has copied into ram at setupdat. the 8051 answers a get_status request (brequest=0) by loading two bytes into the in0buf buffer and loading the byte count register in0bc with the value ?2.? the ez-usb core transmits these two bytes in response to an in token. i n a d d r e n d p c r c 5 token packet d a t a 0 8 bytes setup data c r c 1 6 data packet s e t u p a d d r e n d p c r c 5 token packet d a t a 1 2 bytes c r c 1 6 data packet d a t a 1 data pkt a c k h/s pkt o u t a d d r e n d p c r c 5 token packet c r c 1 6 setup stage sutok interrupt sudav interrupt data stage status stage 8 ram bytes setupdat in0buf 64-byte buffer 2 in0bc a c k h/s pkt a c k h/s pkt
ez-usb technical reference manual page 7-8 ez-usb technical reference manual v1.10 finally, the 8051 clears the hsnak bit (by writing ?1? to it) to instruct the ez-usb core to ack the status stage of the transfer. the following tables show the eight setup bytes for get_status requests. get_status- device queries the state of two bits, remote wakeup and self-powered. the remote wakeup bit indicates whether or not the device is currently enabled to request remote wakeup. remote wakeup is explained in chapter 11, "ez-usb power management." the self-powered bit indicates whether or not the device is self-powered (as opposed to usb bus-powered). the 8051 returns these two bits by loading two bytes into in0buf, and then loading a byte count of two into in0bc. each bulk endpoint (in or out) has a stall bit in its control and status register (bit 0). if the cpu sets this bit, any requests to the endpoint return a stall handshake rather than ack or nak. the get status-endpoint request returns the stall state for the endpoint indicated in byte 4 of the request. note that bit 7 of the endpoint number ep (byte 4) specifies direction. endpoint zero is a control endpoint, which by usb definition is bi-directional . therefore, it has only one stall bit. table 7-3. get status-device (remote wakeup and self-powered bits) byte field value meaning 8051 response 0 bmrequesttype 0x80 in, device 1 brequest 0x00 ?get status? load two bytes into in0buf 2 wvaluel 0x00 3 wvalueh 0x00 byte 0 : bit 0 = self powered bit 4 windexl 0x00 : bit 1 = remote wakeup 5 windexh 0x00 byte 1 : zero 6 wlengthl 0x02 two bytes requested 7 wlengthh 0x00 table 7-4. get status-endpoint (stall bits) byte field value meaning 8051 response 0 bmrequesttype 0x82 in, endpoint load two bytes into in0buf 1 brequest 0x00 ?get status? byte 0 : bit 0 = stall bit for ep(n) 2 wvaluel 0x00 byte 1 : zero 3 wvalueh 0x00 4windexl ep endpoint number ep(n): 5 windexh 0x00 0x00-0x07: out0-out7 6 wlengthl 0x02 two bytes requested 0x80-0x87: in0-in7 7 wlengthh 0x00
chapter 7. ez-usb endpoint zero page 7-9 get_status/interface is easy: the 8051 returns two zero bytes through in0buf and clears the hsnak bit. the requested bytes are shown as ?reserved (reset to zero)? in the usb specifica- tion about stall the usb stall handshake indicates that something unexpected has happened. for instance, if the host requests an invalid alternate setting or attempts to send data to a non-existent end- point, the device responds with a stall handshake over endpoint zero instead of ack or nak. stalls are defined for all endpoint types except isochronous, which do not employ hand- shakes. every ez-usb bulk endpoint has its own stall bit. the 8051 sets the stall condition for an endpoint by setting the stall bit in the endpoint?s cs register. the host tells the 8051 to set or clear the stall condition for an endpoint using the set_feature/stall and clear_feature/stall requests. an example of the 8051 setting a stall bit would be in a routine that handles endpoint zero device requests. if an undefined or non-supported request is decoded, the 8051 should stall ep0. (ep0 has a single stall bit because it is a bi-directional endpoint.) once the 8051 stalls an endpoint, it should not remove the stall until the host issues a clear_feature/stall request. an exception to this rule is endpoint 0, which reports a stall condi- tion only for the current transaction, and then automatically clears the stall condition. this pre- vents endpoint 0, the default control endpoint, from locking out device requests. table 7-5. get status-interface byte field value meaning 8051 response 0 bmrequesttype 0x81 in, endpoint load two bytes into in0buf 1 brequest 0x00 ?get status? byte 0 : zero 2 wvaluel 0x00 byte 1 : zero 3 wvalueh 0x00 4 windexl 0x00 5 windexh 0x00 6 wlengthl 0x02 two bytes requested 7 wlengthh 0x00
ez-usb technical reference manual page 7-10 ez-usb technical reference manual v1.10 7.3.2 set feature set feature is used to enable remote wakeup or stall an endpoint. no data stage is required. the only set_feature/device request presently defined in the usb specification is to set the remote wakeup bit. this is the same bit reported back to the host as a result of a get status- device request (table 7-3). the host uses this bit to enable or disable remote wakeup by the device. the only set_feature/endpoint request presently defined in the usb specification is to stall an endpoint. the 8051 should respond to this request by setting the stall bit in the control and status register for the indicated endpoint ep (byte 4 of the request). the 8051 can either stall an end- point on its own, or in response to the device request. endpoint stalls are cleared by the host clear_feature/stall request. the 8051 should respond to the set_feature/stall request by performing the following steps: 1. set the stall bit in the indicated endpoint?s cs register. 2. reset the data toggle for the indicated endpoint. table 7-6. set feature-device (set remote wakeup bit) byte field value meaning 8051 response 0 bmrequesttype 0x00 out, device set the remote wakeup bit 1 brequest 0x03 ?set feature? 2wvaluel 0x01 feature selector: remote wakeup 3 wvalueh 0x00 4 windexl 0x00 5 windexh 0x00 6 wlengthl 0x00 7 wlengthh 0x00 table 7-7. set feature-endpoint (stall) byte field value meaning 8051 response 0 bmrequesttype 0x02 out, endpoint set the stall bit for the 1 brequest 0x03 ?set feature? indicated endpoint: 2wvaluel 0x00 feature selector: stall 3 wvalueh 0x00 4windexl ep ep(n): 5 windexh 0x00 0x00-0x07: out0-out7 6 wlengthl 0x00 0x80-0x87: in0-in7 7 wlengthh 0x00
chapter 7. ez-usb endpoint zero page 7-11 3. for an in endpoint, clear the busy bit in the indicated endpoint?s cs register. 4. for an out endpoint, load any value into the endpoint?s byte count register. 5. clear the hsnak bit in the ep0cs register (by writing 1 to it) to terminate the set_feature/ stall control transfer. steps 3 and 4 restore the stalled endpoint to its default condition, ready to send or accept data after the stall condition is removed by the host (using a clear_feature/stall request). these steps are also required when the host sends a set_interface request. 7.3.3 clear feature clear feature is used to disable remote wakeup or to clear a stalled endpoint. data toggles the ez-usb core automatically maintains the endpoint toggle bits to ensure data integrity for usb transfers. the 8051 should directly manipulate these bits only for a very limited set of cir- cumstances: ? set_feature/stall ? set_configuration ? set_interface table 7-8. clear feature-device (clear remote wakeup bit) byte field value meaning 8051 response 0 bmrequesttype 0x00 out, device clear the remote wakeup bit 1 brequest 0x01 ?clear feature? 2wvaluel 0x01 feature selector: remote wakeup 3 wvalueh 0x00 4 windexl 0x00 5 windexh 0x00 6 wlengthl 0x00 7 wlengthh 0x00
ez-usb technical reference manual page 7-12 ez-usb technical reference manual v1.10 if the usb device supports remote wakeup (as reported in its descriptor table when the device is enumerated), the clear_feature/remote wakeup request disables the wakeup capability. the clear_feature/stall removes the stall condition from an endpoint. the 8051 should respond by clearing the stall bit in the indicated endpoint?s cs register. 7.3.4 get descriptor during enumeration, the host queries a usb device to learn its capabilities and requirements using get_descriptor requests. using tables of descriptors , the device sends back (over ep0-in) such information as what device driver to load, how many endpoints it has, its different configura- tions, alternate settings it may use, and informative text strings about the device. the ez-usb core provides a special setup data pointer to simplify 8051 service for get_descriptor requests. the 8051 loads this 16-bit pointer with the beginning address of the requested descriptor, clears the hsnak bit (by writing ?1? to it), and the ez-usb core does the rest. table 7-9. clear feature-endpoint (clear stall) byte field value meaning 8051 response 0 bmrequesttype 0x02 out, endpoint clear the stall bit for the 1 brequest 0x01 ?clear feature? indicated endpoint: 2wvaluel 0x00 feature selector: stall 3 wvalueh 0x00 4 windexl ep ep(n): 5 windexh 0x00 0x00-0x07: out0-out7 6 wlengthl 0x00 0x80-0x87: in0-in7 7 wlengthh 0x00
chapter 7. ez-usb endpoint zero page 7-13 figure 7-5. using the setup data pointer (sudptr) for get_descriptor requests figure 7-5 illustrates use of the setup data pointer. this pointer is implemented as two registers, sudptrh and sudptrl. most get_descriptor requests involve transferring more data than will fit into one packet. in the figure 7-5 example, the descriptor data consists of 91 bytes. the control transaction starts in the usual way, with the ez-usb core transferring the eight bytes in the setup packet into ram at setupdat and activating the sudav interrupt request. the 8051 decodes the get_descriptor request, and responds by clearing the hsnak bit (by writ- ing ?1? to it), and then loading the sudptr registers with the address of the requested descriptor. loading the sudptrl register causes the ez-usb core to automatically respond to two in trans- fers with 64 bytes and 27 bytes of data using sudptr as a base address, and then to respond to (ack) the status stage. the usual endpoint zero interrupts, sudav and ep0in, remain active during this automated trans- fer. the 8051 normally disables these interrupts because the transfer requires no 8051 interven- tion. i n a d d r e n d p c r c 5 token packet d a t a 0 8 bytes setup data c r c 1 6 data packet a c k h/s pkt s e t u p a d d r e n d p c r c 5 token packet d a t a 1 payload data c r c 1 6 data packet a c k i n a d d r e n d p c r c 5 token packet d a t a 0 payload data c r c 1 6 data packet a c k h/s pkt setup stage sudav interrupt data stage ep0in interrupt ep0in interrupt status stage d a t a 1 o u t a d d r e n d p c r c 5 token packet c r c 1 6 h/s pkt data pkt a c k h/s pkt sudptrh/l 64 bytes 27 bytes 8 ram bytes setupdat
ez-usb technical reference manual page 7-14 ez-usb technical reference manual v1.10 three types of descriptors are defined: device, configuration, and string. 7.3.4.1 get descriptor-device as illustrated in figure 7-5, the 8051 loads the 2-byte sudptr with the starting address of the device descriptor table. when sudptrl is loaded, the ez-usb core performs the following operations: 1. reads the requested number of bytes for the transfer from bytes 6 and 7 of the setup packet ( lenl and lenh in table 7-11). 2. reads the requested string?s descriptor to determine the actual string length. 3. sends the smaller of (a) the requested number of bytes or (b) the actual number of bytes in the string, over in0buf using the setup data pointer as a data table index. this constitutes the second phase of the three-phase control transfer. the core packetizes the data into multiple data transfers as necessary. 4. automatically checks for errors and re-transmits data packets if necessary. 5. responds to the third (handshake) phase of the control transfer to terminate the opera- tion. the setup data pointer can be used for any get_descriptor request; for example, get_descriptor-string. it can also be used for vendor-specific requests (that you define), as long as bytes 6-7 contain the number of bytes in the transfer (for step 1). it is possible for the 8051 to do manual control transfers, directly loading the in0buf buffer with the various packets and keeping track of which setup phase is in effect. this would be a good usb training exercise, but not necessary due to the hardware support built into the ez-usb core for control transfers. for data stage transfers of fewer than 64 bytes, moving the data into the in0buf buffer and then loading the ep0inbc register with the byte count would be equivalent to loading the setup data pointer. however, this would waste 8051 overhead because the setup data pointer requires no byte transfers into the in0buf buffer. table 7-10. get descriptor- device byte field value meaning 8051 response 0 bmrequesttype 0x80 in, device set sudptr h-l to start of 1 brequest 0x06 ?get_descriptor? device descriptor table in ram 2 wvaluel 0x00 3wvalueh 0x01 descriptor type: device 4 windexl 0x00 5 windexh 0x00 6 wlengthl lenl 7 wlengthh lenh
chapter 7. ez-usb endpoint zero page 7-15 7.3.4.2 get descriptor-configuration 7.3.4.3 get descriptor-string configuration and string descriptors are handled similarly to device descriptors. the 8051 firm- ware reads byte 2 of the setup data to determine which configuration or string is being requested, loads the corresponding table pointer into sudptrh-l, and the ez-usb core does the rest. table 7-11. get descriptor- configuration byte field value meaning 8051 response 0 bmrequesttype 0x80 in, device set sudptr h-l to start of 1 brequest 0x06 ?get_descriptor? requested configuration 2wvaluel cfg config number descriptor table in ram 3wvalueh 0x02 descriptor type: configuration 4 windexl 0x00 5 windexh 0x00 6 wlengthl lenl 7 wlengthh lenh table 7-12. get descriptor- string byte field value meaning 8051 response 0 bmrequesttype 0x80 in, device set sudptr h-l to start of 1 brequest 0x06 ?get_descriptor? requested string descriptor 2 wvaluel str string number table in ram 3 wvalueh 0x03 descriptor type: string 4 windexl 0x00 (language id l) 5 windexh 0x00 (language id h) 6 wlengthl lenl 7 wlengthh lenh
ez-usb technical reference manual page 7-16 ez-usb technical reference manual v1.10 7.3.5 set descriptor table 7-13. set descriptor- device byte field value meaning 8051 response 0 bmrequesttype 0x00 out, device read device descriptor data over 1 brequest 0x07 ?set_descriptor? out0buf 2 wvaluel 0x00 3 wvalueh 0x01 descriptor type: device 4 windexl 0x00 5 windexh 0x00 6 wlengthl lenl 7 wlengthh lenh table 7-14. set descriptor- configuration byte field value meaning 8051 response 0 bmrequesttype 0x00 out, device read configuration descriptor 1 brequest 0x07 ?set_descriptor? data over out0buf 2 wvaluel 0x00 3 wvalueh 0x02 descriptor type: configu- ration 4 windexl 0x00 5 windexh 0x00 6 wlengthl lenl 7 wlengthh lenh table 7-15. set descriptor- string byte field value meaning 8051 response 0 bmrequesttype 0x00 in, device read string descriptor data over 1 brequest 0x07 ?get_descriptor? out0buf 2 wvaluel 0x00 config number 3 wvalueh 0x03 descriptor type: string 4 windexl 0x00 (language id l) 5 windexh 0x00 (language id h) 6 wlengthl lenl 7 wlengthh lenh
chapter 7. ez-usb endpoint zero page 7-17 the 8051 handles set_descriptor requests by clearing the hsnak bit (by writing ?1? to it), then reading descriptor data directly from the out0buf buffer. the ez-usb core keeps track of the number of byes transferred from the host into out0buf, and compares this number with the length field in bytes 6 and 7. when the proper number of bytes has been transferred, the ez-usb core automatically responds to the status phase, which is the third and final stage of the con- trol transfer. note the 8051 controls the flow of data in the data stage of a control transfer. after the 8051 pro- cesses each out packet, it loads any value into the out endpoint?s byte count register to re-arm the endpoint. configurations, interfaces, and alternate settings configurations, interfaces, and alternate set- tings a usb device has one or more configura- tion . only one configuration is active at any time. a configuration has one or more interface , all of which are concurrently active. multiple interfaces allow different host-side device drivers to be associated with different por- tions of a usb device. each interface has one or more alternate setting . each alternate setting has a collec- tion of one or more endpoints. this structure is a software model; the ez-usb core takes no action when these settings change. however, the 8051 must re-initialize endpoints when the host changes configurations or inter- faces alternate settings. as far as 8051 firmware is concerned, a configuration is simply a byte variable that indicates the current setting. the host issues a set_configuration request to select a configuration, and a get_configuration request to determine the current configuration. device config 2 low power config 1 high power interface 1 audio interface 0 cdrom control alt setting 0 alt setting 1 alt setting 3 interface 2 video interface 3 data storage concurrent one at a ti me ep ep ep one at a ti me
ez-usb technical reference manual page 7-18 ez-usb technical reference manual v1.10 7.3.6 set configuration when the host issues the set_configuration request, the 8051 saves the configuration number (byte 2 in table table 7-16), performs any internal operations necessary to support the configura- tion, and finally clears the hsnak bit (by writing ?1? to it) to terminate the set_configuration con- trol transfer. 7.3.7 get configuration table 7-16. set configuration byte field value meaning 8051 response 0 bmrequesttype 0x00 out, device read and stash byte 2, change 1 brequest 0x09 ?set_configuration? configurations in firmware 2 wvaluel cfg config number 3 wvalueh 0x00 4 windexl 0x00 5 windexh 0x00 6 wlengthl 0x00 7 wlengthh 0x00 note after setting a configuration, the host issues set_interface commands to set up the various inter- faces contained in the configuration. table 7-17. get configuration byte field value meaning 8051 response 0 bmrequesttype 0x80 in, device send cfg over in0buf after 1 brequest 0x08 ?get_configuration? re-configuring 2 wvaluel 0x00 3 wvalueh 0x00 4 windexl 0x00 5 windexh 0x00 6 wlengthl 1 lenl 7 wlengthh 0 lenh
chapter 7. ez-usb endpoint zero page 7-19 the 8051 returns the current configuration number. it loads the configuration number into ep0in, loads a byte count of one into ep0inbc, and finally clears the hshak bit (by writing ?1? to it) to ter- minate the set_configuration control transfer. 7.3.8 set interface this confusingly named usb command actually sets and reads back alternate settings for a spec- ified interface. usb devices can have multiple concurrent interfaces. for example a device may have an audio system that supports different sample rates, and a graphic control panel that supports different lan- guages. each interface has a collection of endpoints. except for endpoint 0, which each interface uses for device control, endpoints may not be shared between interfaces. interfaces may report alternate settings in their descriptors. for example, the audio interface may have setting 0, 1, and 2 for 8-khz, 22-khz, and 44-khz sample rates, and the panel interface may have settings 0 and 1 for english and spanish. the set/get_interface requests select between the various alternate settings in an interface. the 8051 should respond to a set_interface request by performing the following steps: ? perform the internal operation requested (such as adjusting a sampling rate). ? reset the data toggles for every endpoint in the interface. ? for an in endpoint, clear the busy bit for every endpoint in the interface. ? for an out endpoint, load any value into the byte count register for every endpoint in the interface. ? clear the hsnak bit (by writing ?1? to it) to terminate the set_feature/stall control transfer. table 7-18. set interface (actually, set alternate setting as for interface if) byte field value meaning 8051 response 0 bmrequesttype 0x00 out, device read and stash byte 2 (as) for 1 brequest 0x0b ?set_interface? interface if, change setting for 2wvaluel as alt setting number interface if in firmware 3 wvalueh 0x00 4windexl if for this interface 5 windexh 0x00 6 wlengthl 0x00 7 wlengthh 0x00
ez-usb technical reference manual page 7-20 ez-usb technical reference manual v1.10 7.3.9 get interface the 8051 simply returns the alternate setting for the requested interface if, and clears the hsnak bit by writing ?1? to it. 7.3.10 set address when a usb device is first plugged in, it responds to device address 0 until the host assigns it a unique address using the set_address request. the ez-usb core copies this device address into the fnaddr (function address) register, and subsequently responds only to requests to this address. this address is in effect until the usb device is unplugged, the host issues a usb reset, or the host powers down. the fnaddr register can be read, but not written by the 8051. whenever the ez-usb core renumerates ? , it automatically resets the fnaddr to zero allowing the device to come back as new . an 8051 program does not need to know the device address, because the ez-usb core automat- ically responds only to the host-assigned fnaddr value. the ez-usb core makes it readable by the 8051 for debug/diagnostic purposes. table 7-19. get interface (actually, get alternate setting as for interface if) byte field value meaning 8051 response 0 bmrequesttype 0x81 in, device send as for interface if over 1 brequest 0x0a ?get_interface? out0buf (1 byte) 2 wvaluel 0x00 3 wvalueh 0x00 4 windexl if for this interface 5 windexh 0x00 6 wlengthl 1 lenl 7 wlengthh 0 lenh
chapter 7. ez-usb endpoint zero page 7-21 7.3.11 sync frame the sync_frame request is used to establish a marker in time so the host and usb device can synchronize multi-frame transfers over isochronous endpoints. suppose an isochronous transmission consists of a repeating sequence of five 300 byte packets transmitted from host to device over ep8-out. both host and device maintain sequence counters that count repeatedly from 1 to 5 to keep track of the packets inside a transmission. to start up in sync, both host and device need to reset their counts to 1 at the same time (in the same frame). to get in sync, the host issues the sync_frame request with ep=ep-out (byte 4). the 8051 firm- ware responds by loading in0buf with a two-byte frame count for some future time; for example, the current frame plus 20. this marks frame ?current+20? as the sync frame, during which both sides will initialize their sequence counters to 1. the 8051 reads the current frame count in the usbframel and usbframeh registers. multiple isochronous endpoints can be synchronized in this manner. the 8051 keeps separate internal sequence counts for each endpoint. table 7-20. sync frame byte field value meaning 8051 response 0 bmrequesttype 0x82 in, endpoint send a frame number over 1 brequest 0x0c ?sync_frame? in0buf to synchronize endpoint 2 wvaluel 0x00 ep 3 wvalueh 0x00 4 windexl ep endpoint number 5 windexh 0x00 ep(n): 6 wlengthl 2 lenl 0x08-0x0f: out8-out15 7 wlengthh 0 lenh 0x88-0x8f: in8-in15 about usb frames the usb host issues a sof (start of frame) packet once every millisecond. every sof packet contains an 11-bit (mod-2048) frame number. the 8051 services all isochronous transfers at sof time, using a single sof interrupt request and vector. if the ez-usb core detects a missing sof packet, it uses an internal counter to generate the sof interrupt.
ez-usb technical reference manual page 7-22 ez-usb technical reference manual v1.10 7.3.12 firmware load the usb endpoint zero protocol provides a mechanism for mixing vendor-specific requests with the previously described standard device requests. bits 6:5 of the bmrequest field are set to 00 for a standard device request, and to 10 for a vendor request. the ez-usb core responds to two endpoint zero vendor requests, ram download and ram upload. these requests are active in all modes (renum=0 or 1). because bit 7 of the first byte of the setup packet specifies direction, only one brequest value (0xa0) is required for the upload and download requests. these ram load commands are avail- able to any usb device that uses the ez-usb chip. a host loader program typically writes 0x01 to the cpucs register to put the 8051 into reset, loads all or part of the ez-usb internal ram with 8051 code, and finally reloads the cpucs regis- ter with 0 to take the 8051 out of reset. the cpucs register is the only usb register that can be written using the firmware download command. table 7-21. firmware download byte field value meaning 8051 response 0 bmrequesttype 0x40 vendor request, out none required 1 brequest 0xa0 ?firmware load? 2wvaluel addrl starting address 3wvalueh addrh 4 windexl 0x00 5 windexh 0x00 6 wlengthl lenl number of bytes 7 wlengthh lenh table 7-22. firmware upload byte field value meaning 8051 response 0 bmrequesttype 0xc0 vendor request, in none required 1 brequest 0xa0 ?firmware load? 2 wvaluel addrl starting address 3 wvalueh addrh 4 windexl 0x00 5 windexh 0x00 6 wlengthl lenl number of bytes 7 wlengthh lenh
chapter 8. ez-usb isochronous transfers page 8-1 chapter 8 ez-usb isochronous transfers 8.1 introduction isochronous endpoints typically handle time-critical, streamed data that is delivered or consumed in byte-sequential order. examples might be audio data sent to a dac over usb, or teleconferenc- ing video data sent from a camera to the host. due to the byte-sequential nature of this data, the ez-usb chip makes isochronous data available as a single byte that represents the head or tail of an endpoint fifo. the ez-usb chips that support isochronous transfers implement sixteen isochronous endpoints, in8-in15 and out8-out15. 1,024 bytes of fifo memory may be distributed over the 16 endpoint addresses. fifo sizes for the isochronous endpoints are programmable. figure 8-1. ez-usb isochronous endpoints 8-15 the 8051 reads or writes isochronous data using sixteen fifo data registers, one per endpoint. these fifo registers are shown in figure 8-1 as inndata (endpoint n in data) and outndata (endpoint n out data). outndata register usb out data usb in data 8051 fifo usb fifo 8051 fifo usb fifo inndata register sof sof (n=8-15) (n=8-15)
ez-usb technical reference manual page 8-2 ez-usb technical reference manual v1.10 the ez-usb core provides a total of 2,048 bytes of fifo memory (1,024 bytes, double-buffered) for iso endpoints. this memory is in addition to the 8051 program/data memory, and normally exists outside of the 8051 memory space. the 1,024 fifo bytes may be divided among the six- teen isochronous endpoints. the 8051 writes sixteen ez-usb registers to allocate the fifo buffer space to the isochronous endpoints. the 8051 also sets endpoint valid bits to enable isoch- ronous endpoints. 8.2 isochronous in transfers in transfers travel from device to host. figure 8-2 shows the ez-usb registers and bits associ- ated with isochronous in transfers. figure 8-2. isochronous in endpoint registers 8.2.1 initialization to initialize an isochronous in endpoint, the 8051 performs the following: ? sets the endpoint valid bit for the endpoint. ? sets the endpoint?s fifo size by loading a starting address (section 8.4, "setting isochro- nous fifo sizes"). ? sets the isosend0 bit in the usbpair register for the desired response. 13 inisoval 0 endpoint valid (1=valid) usbien sofie (1=enabled) in8data 15 14 12 11 8 10 9 5 7 6 4 3 1 2 0 initialization data transfer registers associated with an iso in endpoint (ep8in shown as example) usbirq sofir (1=clear request) 5 7 6 4 3 1 2 0 1 2 3 4 5 6 7 data to usb usbpair isosend0 (see text) 5 2 6 4 3 7 1 0 in8addr fifo start address (see text) a7 a4 a8 a6 a5 a9 0 0
chapter 8. ez-usb isochronous transfers page 8-3 ? enables the sof interrupt. all isochronous endpoints are serviced in response to the sof interrupt. the ez-usb core uses the isosend0 bit to determine what to do if: ? the 8051 does not load any bytes to an inndata register during the previous frame, and ? an in token for that endpoint arrives from the host. if isosend0=0 (the default value), the ez-usb core does not respond to the in token. if isosend0=1, the ez-usb core sends a zero-length data packet in response to the in token. which action to take depends on the overall system design. the isosend0 bit applies to all of the isochronous in endpoints, ep8in through ep15in. 8.2.2 in data transfers when an sof interrupt occurs, the 8051 is presented with empty in fifos that it fills with data to be transferred to the host during the next frame. the 8051 has 1 ms to transfer data into these fifos before the next sof interrupt arrives. to respond to the sof interrupt, the 8051 clears the usb interrupt (8051 int2), and clears the sofir (start of frame interrupt request) bit writing a ?1? to it. then, the 8051 loads data into the appropriate isochronous endpoint. the ez-usb core keeps track of the number of bytes the 8051 loads to each inndata register, and subsequently transfers the correct number of bytes in response to the usb in token during the next frame. the ez-usb fifo swap occurs every sof, even if during the previous frame the host did not issue an in token to read the isochronous fifo data, or if the host encountered an error in the data. usb isochronous data has no re-try mechanism like bulk data. 8.3 isochronous out transfers out transfers travel from host to device. figure 8-3 shows the ez-usb registers and bits associ- ated with isochronous out transfers.
ez-usb technical reference manual page 8-4 ez-usb technical reference manual v1.10 figure 8-3. isochronous out registers 8.3.1 initialization to initialize an isochronous out endpoint, the 8051: ? sets the endpoint valid bit for the endpoint. ? sets the endpoint?s fifo size by loading a starting address (section 8.4, "setting isochro- nous fifo sizes"). ? enables the sof interrupt. all isochronous endpoints are serviced in response to the sof interrupt. registers associated with an iso out endpoint (ep15out shown as example) 13 outisoval endpoint valid (1=valid) usbien sofie (1=enabled) 8 14 12 11 15 10 9 5 7 6 4 3 1 2 0 initialization 0 out15data data transfer usbirq sofir (1=clear request) 5 7 6 4 3 1 2 0 1 2 3 4 5 6 7 received byte count (h) 8 9 2 3 4 5 6 7 received byte count (l) 0 1 2 3 4 5 6 7 out15bch out15bcl isoerr out15 crc error (1=error) 13 10 14 12 11 15 9 8 data from usb out15addr fifo start address (see text) a7 a4 a8 a6 a5 a9 0 0
chapter 8. ez-usb isochronous transfers page 8-5 8.3.2 out data transfer when an sof interrupt occurs, the 8051 is presented with fifos containing out data sent from the host in the previous frame, along with 10-bit byte counts, indicating how many bytes are in the fifos. the 8051 has 1 ms to transfer data out of these fifos before the next sof interrupt arrives. to respond to the sof interrupt, the 8051 clears the usb interrupt (8051 int2), and clears the sofir bit by writing one to it. then, the 8051 reads data from the appropriate outndata fifo register(s). the 8051 can check an error bit in the isoerr register to determine if a crc error occurred for the endpoint data. isochronous data is never present, so the firmware must decide what to do with bad-crc data. 8.4 setting isochronous fifo sizes up to sixteen ez-usb isochronous endpoints share an ez-usb 1,024-byte ram which can be configured as one to sixteen fifos. the 8051 initializes the endpoint fifo sizes by specifying the starting address for each fifo within the 1,024 bytes, starting at address zero. the isochronous fifos can exist anywhere in the 1,024 bytes, but the user must take care to ensure that there is sufficient space between start addresses to accommodate the endpoint fifo size. sixteen start address registers set the isochronous fifo sizes (table 8-1). the ez-usb core con- structs the address writing the 1,024 byte range from the register value as shown in figure 8-4. figure 8-4. fifo start address format a9 a8 a7 a6 a5 a4 0 0 0 0 register address
ez-usb technical reference manual page 8-6 ez-usb technical reference manual v1.10 the size of an isochronous endpoint fifo is determined by subtracting consecutive addresses in table 8-1, and multiplying by four. values written to these registers should have the two lsbs set to zero. the last endpoint, ep15in, has a size of 1,024 minus in15addr times four. because the 10-bit effective address has the four lsbs set to zero (figure 8-4), the fifo sizes are allo- cated in increments of 16 bytes. for example, if out8addr=0x00 and out9addr=0x04, ep8out has a fifo size of the difference multiplied by four or 16 bytes. an 8051 assembler or c compiler may be used to translate fifo sizes into starting addresses. the assembler example in figure 8-5 shows a block of equates for the 16 isochronous fifo sizes, followed by assembler equations to compute the corresponding fifo relative address val- ues. to initialize all sixteen fifo sizes, the 8051 merely copies the table starting at 8outad to the sixteen ez-usb registers starting at out8addr. table 8-1. isochronous endpoint fifo starting address registers register function b7 b6 b5 b4 b3 b2 b1 b0 out8addr endpoint 8 out start address a9a8a7a6a5a4 0 0 out9addr endpoint 9 out start address a9a8a7a6a5a4 0 0 out10addr endpoint 10 out start address a9 a8 a7 a6 a5 a4 0 0 out11addr endpoint 11 out start address a9a8a7a6a5a4 0 0 out12addr endpoint 12 out start address a9 a8 a7 a6 a5 a4 0 0 out13addr endpoint 13 out start address a9 a8 a7 a6 a5 a4 0 0 out14addr endpoint 14 out start address a9 a8 a7 a6 a5 a4 0 0 out15addr endpoint 15 out start address a9 a8 a7 a6 a5 a4 0 0 in8addr endpoint 8 in start address a9 a8 a7 a6 a5 a4 0 0 in9addr endpoint 9 in start address a9 a8 a7 a6 a5 a4 0 0 in10addr endpoint 10 in start address a9 a8 a7 a6 a5 a4 0 0 in11addr endpoint 11 in start address a9 a8 a7 a6 a5 a4 0 0 in12addr endpoint 12 in start address a9 a8 a7 a6 a5 a4 0 0 in13addr endpoint 13 in start address a9 a8 a7 a6 a5 a4 0 0 in14addr endpoint 14 in start address a9 a8 a7 a6 a5 a4 0 0 in15addr endpoint 15 in start address a9 a8 a7 a6 a5 a4 0 0
chapter 8. ez-usb isochronous transfers page 8-7 figure 8-5. assembler translates fifo sizes to addresses the assembler computes starting addresses in figure 8-5 by adding the previous endpoint?s address to the desired size shifted right twice. this aligns a9 with bit 7 as shown in table 8-1. the low operator takes the low byte of the resulting 16 bit expression the user of this code must ensure that the sizes given in the first equate block are all multiples of 16. this is easy to tell by inspection?the least significant digit of the hex values in the first column should be zero. 0100 ep8insz equ 256 ; iso fifo sizes in bytes 0100 ep8outsz equ 256 0010 ep9insz equ 16 0010 ep9outsz equ 16 0010 ep10insz equ 16 0010 ep10outsz equ 16 0000 ep11insz equ 0 0000 ep11outsz equ 0 0000 ep12insz equ 0 0000 ep12outsz equ 0 0000 ep13insz equ 0 0000 ep13outsz equ 0 0000 ep14insz equ 0 0000 ep14outsz equ 0 0000 ep15insz equ 0 0000 ep15outsz equ 0 ; 0000 8outad equ 0 ; load these 16 bytes into addr regs starting out8addr 0040 9outad equ 8outad + low(ep8outsz/4) 0044 10outad equ 9outad + low(ep9outsz/4) 0048 11outad equ 10outad + low(ep10outsz/4) 0048 12outad equ 11outad + low(ep11outsz/4) 0048 13outad equ 12outad + low(ep12outsz/4) 0048 14outad equ 13outad + low(ep13outsz/4) 0048 15outad equ 14outad + low(ep14outsz/4) 0048 8inad equ 15outad + low(ep15outsz/4) 0088 9inad equ 8inad + low(ep8insz/4) 008c 10inad equ 9inad + low(ep9insz/4) 0090 11inad equ 10inad + low(ep10insz/4) 0090 12inad equ 11inad + low(ep11insz/4) 0090 13inad equ 12inad + low(ep12insz/4) 0090 14inad equ 13inad + low(ep13insz/4) 0090 15inad equ 14inad + low(ep14insz/4)
ez-usb technical reference manual page 8-8 ez-usb technical reference manual v1.10 8.5 isochronous transfer speed the amount of data usb can transfer during a 1-ms frame is slightly more than 1,000 bytes per frame (1,500 bytes theoretical, without accounting for usb overhead and bus utilization). a device?s actual isochronous transfer bandwidth is usually determined by how fast the cpu can move data in and out of its isochronous endpoint fifos. the 8051 code example in figure 8-6 shows a typical transfer loop for moving external fifo data into an in endpoint fifo. this code assumes that the 8051 is moving data from an external fifo attached to the ez-usb data bus and strobed by the rd signal, into an internal isochronous in fifo. figure 8-6. 8051 code to transfer data to an isochronous fifo (in8data) the numbers in parentheses indicate 8051 cycles. one cycle is four clocks, and the ez-usb 8051 is clocked at 24 mhz (42 ns). thus, an 8051 cycle takes 4*42=168 ns, and the loop takes 9 cycles or 1.5 s. this loop can transfer about 660 bytes into an in fifo every millisecond (1 ms/ 1.5 s). if more speed is required, the loop can be unrolled by in-line coding the first four instructions in the loop. then, a byte is transferred in 6 cycles (24 clocks) which equates to 1 s per byte. using this method, the 8051 could transfer 1,000 bytes into an in fifo every millisecond. in practice, a bet- ter solution is to in-line code only a portion of the loop code, which decreases full in-line perfor- mance only slightly and uses far fewer bytes of program code. mov dptr,#8000h ; pointer to any outside address inc dps ; switch to second data pointer mov dptr,#in8data ; pointer to an in endpoint fifo (in8 as example) inc dps ; back to first data pointer mov r7,#nbytes ; r7 is loop counter?transfer this many bytes ; loop: movx a,@dptr ; (2) read byte from external bus to acc inc dps ; (2) switch to second data pointer movx @dptr,a ; (2) write to iso fifo inc dps ; (2) switch back to first data pointer djnz r7,loop ; (3) loop ?nbytes? times
chapter 8. ez-usb isochronous transfers page 8-9 8.6 fast transfers ez-usb has a special fast transfer mode for applications that use external fifos connected to the ez-usb data bus. these applications typically require very high transfer speeds in and out of ez- usb endpoint buffers. figure 8-7. 8051 movx instructions the 8051 transfers data to and from ez-usb registers and ram using the movx (move external) instruction (figure 8-7). the 8051 loads one of its two 16-bit data pointers (dptr) with an address in ram, and then executes a movx instruction to transfer data between the accumulator and the byte addressed by dptr. the ?@? symbol indicates that the address is supplied indirectly, by the dptr. the ez-usb core monitors movx transfers between the accumulator and any of the sixteen iso- chronous fifo registers . if an enable bit is set (fiso=1 in the fastxfr register), any read or write to an isochronous fifo register causes the ez-usb core to connect the data to the ez-usb data bus d[7..0], and generate external read/write strobes. one movx instruction thus transfers a byte of data in or out of an endpoint fifo and generates timing strobes for an outside fifo or memory. the 2-cycle movx instruction takes 2 cycles or 333 ns. figures 8-8 and 8-9 show the data flow for fast writes and reads over the ez-usb data bus. fast bulk transfers the ez-usb core provides a special auto-incrementing data pointer that makes the fast transfer mechanism available for bulk transfers. the 8051 loads a 16-bit ram address into the autop- trh/l registers, and then accesses ram data as a fifo using the autodata register. section 6.16, "the autopointer" describes this special pointer and register. movx @dptr,a accumulator dptr ez-usb registers (addressed as external ram) movx a,@dptr
ez-usb technical reference manual page 8-10 ez-usb technical reference manual v1.10 8.6.1 fast writes figure 8-8. fast transfer, ez-usb to outside memory fast writes are illustrated in figure 8-8. when the fast mode is enabled, the dptr points to an isochronous out fifo register, and the 8051 executes the ?movx a,@dptr? instruction, the ez- usb core broadcasts the data from the isochronous fifo to the outside world via the data bus d[7..0], and generates a write strobe fwr# (fast write). a choice of eight waveforms is avail- able for the write strobe, as shown in the next section. 8.6.2 fast reads figure 8-9. fast transfer, outside memory to ez-usb fast reads are illustrated in figure 8-9. when the fast mode is enabled, the dptr points to an isochronous out fifo register, and the 8051 executes the ?movx @dptr,a? instruction, the ez- accumulator dptr iso out fifo fwr# movx a,@dptr d[7..0] external fifo or asic accumulator dptr iso in fifo d[7..0] movx @dptr,a frd# external fifo or asic
chapter 8. ez-usb isochronous transfers page 8-11 usb core breaks the data path from the accumulator to the in fifo register, and instead writes the in fifo using outside data from d[7..0]. the ez-usb core synchronizes this transfer by gen- erating a fifo read strobe frd# (fast read). a choice of eight waveform is available for the read strobe, as shown in the next section. 8.7 fast transfer timing the 8051 sets bits in the fastxfr register to select the fast iso and/or fast bulk mode and to adjust the timing and polarity of the read and write strobes frd# and fwr#. figure 8-10. the fastxfr register controls frd# and fwr# strobes the 8051 sets fiso=1 to select the fast iso mode and fblk=1 to select the fast bulk mode. the 8051 selects read and write strobe pulse polarities with the rpol and wpol bits, where 0=active low, and 1=active high. read and write strobe timings are set by rmod1-rmod0 for read strobes and wmod1-wmod0 for write strobes, as shown in figure 8-11 (write) and figure 8-12 (read). fastxfr fast transfer control 7fe2 b7 b6 b5 b4 b3 b2 b1 b0 fiso fblk rpol rmod1 rmod0 wpol wmod1 wmod0 note when using the fast transfer feature, be sure to enable the frd# and fwr# strobe signals in the portacfg register.
ez-usb technical reference manual page 8-12 ez-usb technical reference manual v1.10 8.7.1 fast write waveforms figure 8-11. fast write timing the timing choices for fast write pulses (fwr#) are shown in figure 8-11. the 8051 can extend the output data and widths of these pulses by setting cycle stretch values greater than zero in the 8051 clock control register ckcon (at sfr location 0x8e). the top five waveforms show the fastest write timings, with a stretch value of 000, which performs the write in eight 8051 clocks. the bottom five waveforms show the same waveforms with a stretch value of 001. clk24 fwr#[00] d[7..0] output tcl 41.66 ns fwr#[01] fwr#[10] fwr#[11] fwr#[00] d[7..0] output fwr#[01] fwr#[10] fwr#[11] note: if wpol=1 the waveforms are inverted stretch=000 stretch=000 stretch=000 stretch=000 stretch=000 stretch=001 stretch=001 stretch=001 stretch=001 stretch=001 [nn] = wm1:wm0, wpol=0
chapter 8. ez-usb isochronous transfers page 8-13 8.7.2 fast read waveforms figure 8-12. fast read timing the timing choices for fast read pulses (frd#) are shown in figure 8-12. read strobe waveforms for stretch values of 000 and 001 are indicated. although two of the read strobe widths can be extended using stretch values greater than 000, the times that the input data is sampled by the ez- usb core remains the same as shown. frd# strobes[00] and [01], along with the osc24 clock signal are typically used to connect to an external synchronous fifo. the on-clock-wide read strobe ensures that the fifo address advances only once per clock. the second strobe [01] is for fifos that put data on the bus one clock after the read strobe. stretch values above 000 serve only to extend the 8051 cycle times, without affecting the width of the frd# strobe. frd# strobes [10] and [11] are typically connected to an external asynchronous fifo, where no clock is required. strobe [10] samples the data at the same time as strobe [11], but provides a osc24 frd#[00] d[7..0] in tcl 41.66 ns frd#[10] frd#[11] d[7..0] in d[7..0] d[7..0] in in frd#[01] frd#[10] frd#[11] stretch=000, 001 stretch=000, 001 stretch=000 stretch=001 stretch=000 stretch=001 note: if wpol=1 the waveforms are inverted [nn] = rmod1:rmod0, rpol=0
ez-usb technical reference manual page 8-14 ez-usb technical reference manual v1.10 wider pulse width (for stretch=000), which is required by some audio codecs. timing values for these strobe signals are given in chapter 13, ?ez-usb ac/dc parameters.? 8.8 fast transfer speed the 8051 code example in figure 8-13 shows a transfer loop for moving external fifo data into the endpoint 8-in fifo. this code moves data from an external fifo attached to the ez-usb data bus and strobed by the frd# signal, into the fifo register in8data figure 8-13. 8051 code to transfer 640 bytes of external data to an isochronous in fifo this routine uses a combination of in-line and looped code to transfer 640 bytes into the ep8in fifo from an external fifo. the loop transfers eight bytes in 19 cycles, and it takes 80 times through the loop to transfer 640 bytes. therefore, the total transfer time is 80 times 19 cycles, or 1,520 cycles. the 640 byte transfer thus takes 1,520*166 ns or 252 s, or approximately one- fourth of the 1-ms usb frame time. using this routine, the time to completely fill one isochronous fifo with 1,024 bytes (assuming all 1,024 isochronous fifo bytes are assigned to one endpoint) would be 128 times 19 cycles, or 2,432 cycles. the 1,024 byte transfer would take 403 s, less than half of the 1-ms usb frame time. if still faster time is required, the routine can be modified to put more of the movx instructions in- line. for example, with 16 in-line movx instructions, the transfer time for 1,024 bytes would be 35 cycles times 64 loops or 2,240 cycles, or 371 s, an 8% speed improvement over the eight instruc- tion loop. (init) mov dptr,#fastxfr ; set up the fast iso transfer mode mov a,#10000000b ; fiso=1, rpol=0, rm1-0 = 00 movx @dptr,a ; load the fastxfr register mov dptr,#in8data ; pointer to in endpoint fifo mov r7,#80 ; r7 is loop counter, 8 bytes per loop ; loop: movx @dptr,a ; (2) write in fifo using byte from external bus movx @dptr,a ; (2) again movx @dptr,a ; (2) again movx @dptr,a ; (2) again movx @dptr,a ; (2) again movx @dptr,a ; (2) again movx @dptr,a ; (2) again movx @dptr,a ; (2) again djnz r7,loop ; (3) do eight more, ?r7? times
chapter 8. ez-usb isochronous transfers page 8-15 8.9 other isochronous registers two additional registers, isoctl and zbcout, provide additional isochronous endpoint features. 8.9.1 disable iso figure 8-14. isoctl register bit zero of the isoctl register is called isodisab. when the 8051 sets isodisab=1, all sixteen of ez-usb endpoints are disabled. if isodisab=1, ep8in=ep15in and ep8out-ep15out should not be used. isodisab is cleared at power-on. when isodisab=1, the 2,048 bytes of ram normally used for isochronous buffers is available to the 8051 as xdata ram ( not program memory), from 0x2000 to 0x27ff in internal memory. when isodisab=1, the behavior of the rd# and wr# strobe signals changes to reflect the addi- tional 2 kb of memory inside the ez-usb chip. this is shown in table 8-2. isoctl register bits shown as mbz (must be zero) must be written with zeros. the ppstat bit toggles every sof, and may be written with any value (no effect). therefore, to disable the isoch- ronous endpoints, the 8051 should write the value 0x01 to the isoctl register. isoctl isochronous control 7fa1 b7 b6 b5 b4 b3 b2 b1 b0 - - - - ppstat mbz mbz isodisab table 8-2. addresses for rd# and wr# vs. isodisab bit isodisab rd#, wr# 0 (default) 2000-7b40, 8000-ffff 1 2800 -7b40, 8000-ffff caution! if you use this option, be absolutely certain that the host never sends isochronous data to your device. isochronous data directed to a disabled isochronous endpoint system will cause unpre- dictable operation.
ez-usb technical reference manual page 8-16 ez-usb technical reference manual v1.10 8.9.2 zero byte count bits when the sof interrupt is asserted, the 8051 normally checks the isochronous out endpoint fifos for data. before reading the byte count registers and unloading an isochronous fifo, the firmware may wish to check for a zero byte count. in this case, the 8051 can check bits in the zbcout register. any endpoint bit set to ?1? indicates that no out bytes were received for that endpoint during the previous frame. figure 8-15 shows this register. figure 8-15. zbcout register the ez-usb core updates these bits every sof. 8.10 iso in response with no data the isosend0 bit (bit 7 in the usbpair register) is used when the ez-usb chip receives an iso- chronous in token while the in fifo is empty. if isosend0=0 (the default value) the ez-usb core does not respond to the in token. if isosend0=1, the ez-usb core sends a zero-length data packet in response to the in token. which action to take depends on the overall system design. the isosend0 bit applies to all of the isochronous in endpoints, in-8 through in-15. note the autopointer is not usable from 0x2000-0x27ff (the reclaimed iso buffer ram) when iso- disab=1. zbcout zero byte count bits 7fa2 b7 b6 b5 b4 b3 b2 b1 b0 ep15 ep14 ep13 ep12 ep11 ep10 ep9 ep8
chapter 8. ez-usb isochronous transfers page 8-17 8.11 using the isochronous fifos there is a window of time before and after each sof (start of frame) when accessing the isochro- nous fifos will cause data corruption or loss of data. this is because each isochronous endpoint is actually a pair of fifos, and the fifos are swapped at sof time. the swap occurs about 10 s before the sof interrupt signals the 8051 code. (between sofs, one fifo of the pair is accessible to the 8051, while the other fifo of the pair transfers data to or from the usb.) workaround#1: if you can pre-assemble the data into a buffer, blast the data (in a tight loop) into the new fifo just after the sof interrupt, typically inside the sof isr (interrupt service routine). workaround#2: if you can?t pre-assemble the data into a buffer, prevent access during sofs by setting a time (in the sof isr) to time out and halt access just before the next sof. set the timer for about 950 s (ms minus 50 s). be careful of interrupt latency delaying the timeout isr. that is, the timeout isr may be prevented from halting access by getting preempted by a higher priority interrupt(s), made worse by the nec- essary practice of disabling interrupts to manage shared resources, resources that are shared between the isrs and background process. to prevent drift of the timer relative to sofs, restart the timer after each sof (typically in the sof isr).
ez-usb technical reference manual page 8-18 ez-usb technical reference manual v1.10
chapter 9. ez-usb interrupts page 9-1 chapter 9 ez-usb interrupts 9.1 introduction the ez-usb enhanced 8051 responds to the interrupts shown in table 9-1. interrupt sources that are not present in the standard 8051 are shown as checked in the ?new? column. the three inter- rupts used by the ez-usb core are shown in bold type. the natural priority column in table 9-1 shows the 8051 interrupt priorities. as explained in appendix c, the 8051 can assign each interrupt to a high or low priority group. the 8051 resolves priorities within the groups using the natural priorities. table 9-1. ez-usb interrupts new 8051 interrupt (irq name) source vector (hex) natural priority ie0 int0# pin 03 1 tf0 timer 0 overflow 0b 2 ie1 int1# pin 13 3 tf1 timer 1 overflow 1b 4 ri_0 & ti_0 uart0 rx & tx 23 5 p tf2 timer 2 overflow 2b 6 p resume (pfi) wakeup# pin or usb core 33 0 p ri_1 & ti_1 uart1 rx & tx 3b 7 p usb (int2) usb core 43 8 p i 2 c (int3) usb core 4b 9 p ie4 in4 pin 53 10 p ie5 int5# pin 5b 11 p ie6 int6 pin 63 12
ez-usb technical reference manual page 9-2 ez-usb technical reference manual v1.10 9.2 usb core interrupts the ez-usb core provides three interrupt request types, which are described in the following sec- tions: wakeup - after the ez-usb chip detects usb suspend and the 8051 has entered its idle state, the ez-usb core responds to an external signal on its wakeup# pin or resumption of usb bus activity by re-starting the ez-usb oscillator and resuming 8051 operation. usb signaling - these include 16 bulk endpoint interrupts, three interrupts not specific to a particular endpoint (sof), suspend, usb reset), and two interrupts for con- trol transfers (sutok, sudav). these interrupts share the usb interrupt (int2). i 2 c transfers - (int3). 9.3 wakeup interrupt chapter 10, "ez-usb resets" describes suspend-resume signaling in detail, along with a code example that uses the wakeup interrupt. briefly, the usb host puts a device into suspend by stopping bus activity to the device. when the ez-usb core detects 3 ms of no bus activity, it activates the usb suspend interrupt request. if enabled, the 8051 takes the suspend interrupt, does power management housekeeping (shutting down power to external logic), and finishes by setting sfr bit pcon.0. this signals the ez-usb core to enter a very low power mode by turning off the 12-mhz oscillator. when the 8051 sets pcon.0, it enters an idle state. 8051 execution is resumed by activation of any enabled interrupt. the ez-usb chip uses a dedicated interrupt for usb resume. when external logic pulls wakeup# low (for example, when a keyboard key is pressed or a modem receives a ring signal) or usb bus activity resumes, the ez-usb core re-starts the 12-mhz oscilla- tor, allowing the 8051 to recognize the interrupt and continue executing instructions.
chapter 9. ez-usb interrupts page 9-3 figure 9-1. ez-usb wakeup interrupt figure 9-1 shows the 8051 sfr bits associated with the resume interrupt. the ez-usb core asserts the resume signal when the ez-usb core senses a usb global resume, or when the ez- usb wakeup# pin is pulled low. the 8051 enables the resume interrupt by setting eicon.5. the 8051 reads the resume interrupt request bit in eicon.4, and clears the interrupt request by writing a zero to eicon.4. 9.4 usb signaling interrupts figure 9-2 shows the 21 usb requests that share the 8051 usb (int2) interrupt. the bottom irq, ep7-out, is expanded in the diagram to show the logic associated with each usb interrupt request. tb eicon.5 ; enable resume interrupt resume_isr: clr eicon.4 ; clear the 8051 w/u ; interrupt request reti eicon.5 eicon.4(rd) eicon.4(0) s r 8051 "resume" interrupt resume signal from ez-usb core
ez-usb technical reference manual page 9-4 ez-usb technical reference manual v1.10 figure 9-2. usb interrupts referring to the logic inside the dotted lines, each usb interrupt source has an interrupt request latch. the ez-usb core sets an irq bit, and the 8051 clears an irq bit by writing a ?1? to it. the output of each latch is anded with an ien (interrupt enable) bit and then ored with all the other usb interrupt request sources. the ez-usb core prioritizes the usb interrupts, and constructs an autovector, which appears in the ivec register. the interrupt vector values iv[4..0] are shown to the left of the interrupt sources (shaded boxes). 00 is the highest priority, 15 is the lowest. if two usb interrupts occur simulta- neously, the prioritization affects which one is first indicated in the avec register. if the 8051 has enabled autovectoring, the ivec byte replaces byte 0x45 in 8051 program memory. this causes 8051 ez-usb ep0-in ep0-out ep1-in ep1-out ep2-in ep2-out ep3-in ep3-out sutok sudav sof susp eie.0 exif.4(rd) exif.4(0) s r 8051 "usb" interrupt out07ien.7 in07irq.7(1) s r in07irq.7 (rd) ures ep4-in ep4-out ep5-in ep5-out ep6-in ep6-out ep7-in ep7-out 0 iv4 iv3 iv2 iv1 iv0 0 0 ivec 00 01 02 03 04 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 interrupt request latch ibn int 05
chapter 9. ez-usb interrupts page 9-5 the usb interrupt automatically to vector to different addresses for each usb interrupt source. this mechanism is explained in detail in section 9.10, "usb autovectors." due to the or gate in figure 9-2, any of the usb interrupt sources sets the 8051 usb interrupt request latch, whose state appears as an interrupt request in the 8051 sfr bit exif.4. the 8051 enables the usb interrupt by setting sfr bit eie.0. to clear the usb interrupt request the 8051 writes a zero to the exif.4 bit. note that this is the opposite of clearing any of the individual usb interrupt sources, which the 8051 does by writing a ?1? to the irq bit. when a usb resource requires service (for example, a sof token arrives or an out token arrives on a bulk endpoint), two things happen. first, the corresponding interrupt request latch is set. second, a pulse is generated, ored with the other usb interrupt logic, and routed to the 8051 int2 input. the pulse is required because int2 is edge triggered. when the 8051 finishes servicing a usb interrupt, it clears the particular irq bit by writing a ?1? to it. if any other usb interrupts are pending, the act of clearing the irq causes the ez-usb core logic to generate another pulse for the highest-priority pending interrupt. if more that one is pend- ing, they are serviced in the priority order shown in figure 9-2, starting with sudav (priority 00) as the highest priority, and ending with ep7-out (priority 15) as the lowest. figure 9-3 illustrates a typical usb isr for endpoint 2-in. important it is important in any usb interrupt service routine (isr) to clear the 8051 int2 interrupt before clearing the particular usb interrupt request latch. this is because as soon as the usb interrupt is cleared, any pending usb interrupt will pulse the 8051 int2 input, and if the int2 interrupt request latch has not been previously cleared the pending interrupt will be lost.
ez-usb technical reference manual page 9-6 ez-usb technical reference manual v1.10 figure 9-3. the order of clearing interrupt requests is important usb_isr: push dps push dpl push dph push dpl1 push dph1 push acc ; mov a,exif ; first clear the usb (int2) interrupt request clr acc.4 mov exif,a ; note: exif reg is not 8051 bit-addressable ; mov dptr,#in07irq ; now clear the usb interrupt request mov a,#00000100b ; use in2 as example movx @dptr,a ; ; (perform interrupt routine stuff) ; pop acc pop dph1 pop dpl1 pop dph pop dpl pop dps ; reti
chapter 9. ez-usb interrupts page 9-7 figure 9-4. ez-usb interrupt registers figure 9-4 shows the registers associated with the usb interrupts. each interrupt source has an enable (ien) and a request (irq) bit. the 8051 sets the ien bit to enable the interrupt. the usb core sets an irq bit high to request an interrupt, and the 8051 clears an irq bit by writing a ?1? to it. in07irq endpoints 0-7 in interrupt requests 7fa9 b7 b6 b5 b4 b3 b2 b1 b0 in7ir in6ir in5ir in4ir in3ir in2ir in1ir in0ir out07irq endpoints 0-7 out interrupt requests 7faa b7 b6 b5 b4 b3 b2 b1 b0 out7ir out6ir out5ir out4ir out3ir out2ir out1ir out0ir usbirq usb interrupt request 7fab b7 b6 b5 b4 b3 b2 b1 b0 - - - usesir suspir sutokir sofir sudavir in07ien endpoints 0-7 in interrupt enables 7fac b7 b6 b5 b4 b3 b2 b1 b0 in7ien in6ien in5ien in4ien in3ien in2ien in1ien in0ien out07ien endpoints 0-7 out interrupt enables 7fad b7 b6 b5 b4 b3 b2 b1 b0 out7ien out6ien out5ien out4ien out3ien out2ien out1ien out0ien usbien usb interrupt enables 7fae b7 b6 b5 b4 b3 b2 b1 b0 - - - uresie suspie sutokie sofie sudavie
ez-usb technical reference manual page 9-8 ez-usb technical reference manual v1.10 the usbien and usbirq registers control the first five interrupts shown in figure 9-2. the in07ien and out07 registers control the remaining 16 usb interrupts, which correspond to the 16 bulk endpoints in0-in7 and out0-out7. the 21 usb interrupts are now described in detail. 9.5 sutok, sudav interrupts figure 9-5. sutok and sudav interrupts sutok and sudav are supplied to the 8051 by ez-usb control endpoint zero. the first por- tion of a usb control transfer is the setup stage shown in figure 9-5. (a full control transfer is the setup stage shown in figure 7-1.) when the ez-usb core decodes a setup packet, it asserts the sutok (setup token) interrupt request. after the ez-usb core has received the eight bytes error-free and copied them into eight internal registers at setupdat, it asserts the sudav interrupt request. the 8051 program responds to the sudav interrupt by reading the eight setup data bytes in order to decode the usb request (chapter 7, "ez-usb endpoint zero"). the sutok interrupt is provided to give advance warning that the eight register bytes at setup- dat are about to be over-written. it is useful for debug and diagnostic purposes. 9.6 sof interrupt figure 9-6. a start of frame (sof) packet d a t a 0 8 bytes setup data c r c 1 6 data packet a c k h/s pkt s e t u p a d d r e n d p c r c 5 token packet setup stage sutok interru p t sudav interru p t s o f f r n o c r c 5 token pkt
chapter 9. ez-usb interrupts page 9-9 usb start of frame interrupt requests occur every millisecond. when the ez-usb core receives an sof packet, it copies the eleven-bit frame number (frno in figure 9-6) into the usbframeh and usbframel registers, and activates the sof interrupt request. the 8051 services all isoch- ronous endpoint data as a result of the sof interrupt. 9.7 suspend interrupt if the ez-usb detects 3 ms of no bus activity, it activates the susp (suspend) interrupt request. a full description of suspend-resume signaling appears in chapter 11, "ez-usb power manage- ment." 9.8 usb reset interrupt the usb signals a bus reset by driving both d+ and d- low for at least 10 ms. when the ez-usb core detects the onset of usb bus reset, it activates the ures interrupt request. 9.9 bulk endpoint interrupts the remaining 16 usb interrupt requests are indexed to the 16 ez-usb bulk endpoints. the ez- usb core activates a bulk interrupt request when the endpoint buffer requires service. for an out endpoint, the interrupt request signifies that out data has been sent from the host, validated by the ez-usb core, and is sitting in the endpoint buffer memory. for an in endpoint, the interrupt request signifies that the data previously loaded by the 8051 into the in endpoint buffer has been read and validated by the host, making the in endpoint buffer ready to accept new data. the ez-usb core sets an endpoint?s interrupt request bit when the endpoint?s busy bit (in the end- point cs register) goes low, indicating that the endpoint buffer is available to the 8051. for exam- ple, when endpoint 4-out receives a data packet, the busy bit in the out4cs register goes low, and out07irq.4 goes high, requesting the endpoint 4-out interrupt. 9.10 usb autovectors the usb interrupt is shared by 21 interrupt sources. to save the code and processing time required to sort out which usb interrupt occurred, the ez-usb core provides a second level of interrupt vectoring, called ?autovectoring.? when the 8051 takes a usb interrupt, it pushes the program counter onto its stack, and then executes a jump to address 43, where it expects to find a jump instruction to an interrupt service routine. the 8051 jump instruction is encoded as follows:
ez-usb technical reference manual page 9-10 ez-usb technical reference manual v1.10 if autovectoring is enabled (aven=1 in the usbbav register), the ez-usb core substitutes its avec byte for the byte at address 0x0045. therefore, if the programmer pre-loads the high byte (?page?) of a jump table address at location 0x0044, the core-inserted byte at 0x45 will automati- cally direct the jump to one of 21 addresses within the page. in the jump table, the programmer then puts a series of jump instructions to each particular isr. table 9-2. 8051 jump instruction address op-code hex value 0043 jump 0x02 0044 addrh 0xhh 0045 addrl 0xll table 9-3. a typical usb jump table table offset instruction 00 jmp sudav_isr 04 jmp sof_isr 08 jmp sutok_isr 0c jmp suspend_isr 10 jmp usbreset_isr 14 jmp ibn_isr (2122/2126 only, otherwise nop) 18 jmp ep0in _isr 1c jmp ep0out_isr 20 jmp in1buf_isr 24 jmp ep1out_isr 28 jmp ep2in_isr 2c jmp ep2out_isr 30 jmp ep3in_isr 34 jmp ep3out_isr 38 jmp ep4in_isr 3c jmp ep4out_isr 40 jmp ep5in_isr 44 jmp ep5out_isr 48 jmp ep6in_isr 4c jmp ep6out_isr 50 jmp ep7in_isr 54 jmp ep7out_isr
chapter 9. ez-usb interrupts page 9-11 9.11 autovector coding a detailed example of a program that uses autovectoring is presented in section 6.14, "interrupt bulk transfer example." the coding steps are summarized here. to employ ez-usb autovector- ing: 1. insert a jump instruction at 0x43 to a table of jump instructions to the various usb interrupt service routines. 2. code the jump table with jump instructions to each individual usb interrupt service routine. this table has two important requirements, arising from the format of the avec byte (zero- based, with 2 lsbs set to 0): ?it must begin on a page boundary (address 0xnn00). ?the jump instructions must be four bytes apart. ?the interrupt service routines can be placed anywhere in memory. ?write initialization code to enable the usb interrupt (int2), and autovectoring. figure 9-7. the autovector mechanism in action figure 9-7 illustrates an isr that services endpoint 2-out. when endpoint 2-out requires ser- vice, the ez-usb core activates the usb interrupt request, vectoring the 8051 to location 0x43. the jump instruction at this location, which was originally coded as ?ljmp 04- 00 ? becomes ?ljmp 04- 2c ? due to the ez-usb core substituting 2c as the autovector byte for endpoint 2-out (table 9-3). the 8051 jumps to 042c, where it executes the jump instruction to the endpoint 2- out isr shown in this example at address 0119. once the 8051 takes the vector at 0043, initia- tion of the endpoint-specific isr takes only eight 8051 cycles. ep2out_isr: usb_jmp_table: ljmp 04 (00)2c 0043 0044 0045 2c avec usb core ljmp ep2out_isr 01 19 042c 042d 042e 0400 0119 8051 usb interrupt vector
ez-usb technical reference manual page 9-12 ez-usb technical reference manual v1.10 9.12 i 2 c interrupt figure 9-8. i 2 c interrupt enable bits and registers chapter 4, "ez-usb input/output" describes the 8051 interface to the ez-usb i 2 c controller. the 8051 uses two registers, i2cs (i 2 c control and status) and i2dat (i 2 c data) to transfer data over the i 2 c bus. the ez-usb core signals completion of a byte transfer by setting the done bit (i2cs.0) high, which also sets an i 2 c interrupt request latch (figure 9-8). this interrupt request is routed to the 8051 int3 interrupt. the 8051 enables the i 2 c interrupt by setting eie.1=1. the 8051 determines the state of the inter- rupt request flag by reading exif.5, and resets the int3 interrupt request by writing a zero to exif.5. any 8051 read or write to the i2dat or i2cs register automatically clears the i 2 c interrupt request. eie.1 exif.5(rd) exif.5(0) s r 8051 i 2 c-compatible interrupt (int3) i 2 c-compatible interrupt request done s r rd or wr i2dat register i2cs i2dat start stop lastrd id1 id0 berr ack d7 d6 d5 d4 d3 d2 d1 d0 done ez-usb 8051
chapter 9. ez-usb interrupts page 9-13 9.13 i 2 c registers figure 9-9. i 2 c control and status register figure 9-10. i 2 c data the two registers that the 8051 uses to control i 2 c transfers are shown above. in the ez-usb family, an i 2 c interrupt request occurs on int3 whenever the done bit (i2cs.0) makes a 0-to-1 transition. this interrupt signals the 8051 that the i 2 c controller is ready for another command. the 8051 concludes i 2 c transfers by setting the stop bit (i2cs.6). when the stop condition has been sent over the i 2 c bus, the i 2 c controller resets i2cs.6 to zero. during the time the i 2 c con- troller is generating the stop condition, it ignores accesses to the i2cs and i2dat registers. the 8051 code should therefore check the stop bit for zero before writing new data to i2cs or i2dat. in the ez-usb family, it does this by polling the i2cs.6 bit. i2cs i 2 c control and status 7fa5 b7 b6 b5 b4 b3 b2 b1 b0 start stop lastrd id1 id0 berr ack done r/w r/w r/w r r r r r 0 0 0 x x 0 0 0 i2dat i 2 c data 7fa6 b7 b6 b5 b4 b3 b2 b1 b0 d7 d6 d5 d4 d3 d2 d1 d0 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x
ez-usb technical reference manual page 9-14 ez-usb technical reference manual v1.10
chapter 10. ez-usb resets page 10-1 chapter 10 ez-usb resets 10.1 introduction the ez-usb chip has three resets: ? a power-on reset (por), which turns on the ez-usb chip in a known state. ? an 8051 reset, controlled by the ez-usb core. ? a usb bus reset, sent by the host to reset a device. this chapter describes the effects of these three resets. 10.2 ez-usb power-on reset (por) figure 10-1. ez-usb resets reset res ez-usb core 8051 res cpucs.0 (1 at pwr on) oscillator xin xout pll 2 12 mhz clk24 24 mhz 48 mhz usb bus reset vcc
ez-usb technical reference manual page 10-2 ez-usb technical reference manual v1.10 when power is first applied to the ez-usb chip, the external r-c circuit holds the ez-usb core in reset until the on-chip pll stabilizes. the clk24 pin is active as soon as power is applied. the 8051 may clear an ez-usb control bit, clk24oe, to inhibit the clk24 output pin for emi-sensitive applications that do not need this signal. external logic can force a chip reset by pulling the reset pin hi. the reset pin is normally connected to vcc through a 1 f capacitor and to gnd through a 10-k resistor (figure 10-1). the oscillator and pll are unaffected by the state of the reset pin. the clk24 signal is active while reset = hi. when reset returns lo, the activity on the clk24 pin depends on whether or not the ez-usb chip is in suspend state. if in suspend, clk24 stops. resumption of usb bus activity or asserting the wakeup# pin lo re-starts the clk24 sig- nal. power-on default values for all ez-usb register bits are shown in chapter 12, "ez-usb regis- ters." table 10-1 summarizes reset states that affect usb device operation. note that the term ?power-on reset? refers to a reset initiated by application of power, or by assertion of the reset pin. * when the 8051 is released from reset, the ez-usb automatically arms the bulk out endpoints by setting their cs registers to 000000010b. table 10-1. ez-usb states after power-on reset (por) item register default value comment 1 endpoint data xxxxxxxx 2 byte counts xxxxxxxx 3 cpucs rrrr0011 rrrr=rev number, b1 =clk24oe, b0=8051res 4 port configs 00000000 io, not alternate functions 5 port registers xxxxxxxx 6 port oes 00000000 inputs 7 interrupt enables 00000000 disabled 8 interrupt reqs 00000000 cleared 9 bulk in c/s 00000000 bulk in endpoints not busy (unarmed) 10 bulk out c/s* 00000000 bulk out endpoints not busy (unarmed) 11 toggle bits 00000000 data toggles = 0 12 usbcs 00000100 renum=0, discoe=1 (discon pin drives) 13 fnaddr 00000000 usb function address 14 in07val 01010111 ep0,1,2,4,6 in valid 15 out07val 01010101 ep0,2,4,6 out valid 16 inisoval 00000111 ep8,9,10 in valid 17 outisoval 00000111 ep8,910out valid 18 usbpair 0x000000 isosend0 (b7) = 0, no pairing 19 usbbav 00000000 break condition cleared, no autovector 20 configuration 0 internal ez-usb core value 21 alternate setting 0 internal ez-usb core value
chapter 10. ez-usb resets page 10-3 from table 10-1, at power-on: ? endpoint data buffers and byte counts are un-initialized (1,2). ? the 8051 is held in reset, and the clk24 pin is enabled (3). ? all port pins are configured as input ports (4-6). ? usb interrupts are disabled, and usb interrupt requests are cleared (7-8). ? bulk in and out endpoints are unarmed, and their stall bits are cleared (9). the ez-usb core will nak in or out tokens while the 8051 is reset. out endpoints are enabled when the 8051 is released from reset. ? endpoint toggle bits are cleared (11). ? the renum bit is cleared. this means that the ez-usb core, and not the 8051, initially responds to usb device requests (12). ? the usb function address register is set to zero (13). ? the endpoint valid bits are set to match the endpoints used by the default usb device (14- 17). ? endpoint pairing is disabled. also, isosend0=0, meaning that if an isochronous endpoint receives an in token without being loaded by the 8051 in the previous frame, the ez-usb core does not generate any response (18). ? the breakpoint condition is cleared, and autovectoring is turned off (19). ? configuration zero, alternate setting zero is in effect (20-21). 10.3 releasing the 8051 reset the ez-usb register bit cpucs.0 resets the 8051. this bit is hi at power-on, initially holding the 8051 in reset. there are three ways to release the 8051 from reset: ? by the host, as the final step of a ram download. ? automatically, as part of an eeprom load. ? automatically, when external rom is used (ea=1).
ez-usb technical reference manual page 10-4 ez-usb technical reference manual v1.10 10.3.1 ram download once enumerated, the host can download code into the ez-usb ram using the ?firmware load? vendor request (chapter 7, "ez-usb endpoint zero"). the last packet loaded writes 0 to the cpucs register, which clears the 8051 reset bit. 10.3.2 eeprom load chapter 5 describes the eeprom boot loads in detail. briefly, at power-on, the ez-usb core checks for the presence of an eeprom on its i 2 c bus. if found, it reads the first eeprom byte. if it reads 0xb2 as the first byte, the ez-usb core downloads 8051 code from the eeprom into internal ram. the last byte of a ?b2? load writes 0x00 to the cpucs register (at 0x7f92), which releases the 8051 from reset. 10.3.3 external rom ez-usb systems can use external program memory containing 8051 code and usb device descriptors, which include the vid/did/pid bytes. because these systems do no require and i 2 c eeprom to supply the vid/did/pid, the ez-usb core automatically releases 8051 reset when: 1. ea=1 (external code memory), and 2. no ?b0/b2? eeprom is detected on the i 2 c bus. the ez-usb core also sets the renum bit to ?1,? giving usb control to the 8051. 10.4 8051 reset effects once the 8051 is running, the usb host may reset the 8051 by downloading the value 0x01 to the cpucs register. the host might do this in preparation for loading code overlays, effectively mag- nifying the size of the internal ez-usb ram. for such applications it is important to know the state of the ez-usb chip during and after an 8051 reset. in this section, this particular reset is called an ?8051 reset,? and should not be confused with the por described in section 10.2, "ez- usb power-on reset (por)." this discussion applies only to the condition where the ez-usb chip is powered, and the 8051 is reset by the host setting the cpucs register to 0. note the other bit in the cpucs register, clk24oe, is writable only by the 8051, so the host writing a zero byte to this register does not turn off the clk24 signal.
chapter 10. ez-usb resets page 10-5 the basic usb device configuration remains intact through an 8051 reset. valid endpoints remain valid, the usb function address remains the same, and the io ports retain their configurations and values. stalled endpoints remain stalled, and data toggles don?t change. the only effects of an 8051 reset are as follows: ? usb interrupts are disabled, but pending interrupt requests remain pending. ? during the 8051 reset, all bulk endpoints are unarmed, causing the ez-usb core to nak and in or out tokens. ? after the 8051 reset is removed, the out bulk endpoints are automatically armed. out endpoints are thus ready to accept one out packet before 8051 intervention is required. ? the breakpoint condition is cleared. the renum bit is not affected by an 8051 reset. when the 8051 comes out of reset, the pending interrupts are kept pending, but disabled (1). this gives the firmware writer the choice of acting on pre-8051-reset usb events, or ignoring them by clearing the pending interrupt(s). during the 8051 reset time, the ez-usb core holds off any usb traffic by naking in and out tokens (2). the ez-usb core automatically arms the out endpoints when the 8051 exits the reset state (3). usbbav.3, the breakpoint break bit, is cleared (4). the other bits in the usbbav register are unaffected.
ez-usb technical reference manual page 10-6 ez-usb technical reference manual v1.10 10.5 usb bus reset the host signals a usb bus reset by driving an se0 state (both d+ and d- data lines low) for a minimum of 10 ms. the ez-usb core senses this condition, requests the 8051 usb interrupt (int2), and supplies the interrupt vector for a usb reset. a usb reset affects the ez-usb resources as shown in table 10-2. a usb bus reset leaves most ez-usb resources unchanged. from table 10-2, after usb bus reset: ? the ez-usb core unarms all bulk in endpoints (9). data loaded by the 8051 into an in endpoint buffer remains there, and the 8051 firmware can either re-send it by loading the endpoint byte count register to re-arm the transfer, or send new data by re-loading the in buffer before re-arming the endpoint. ? bulk out endpoints retain their busy states (10). data sent by the host to an out end- point buffer remains in the buffer, and the 8051 firmware can either read the data or reject table 10-2. ez-usb states after a usb bus reset item register default value comment 1 endpt data uuuuuuuu u = unchanged 2 byte counts uuuuuuuu 3 cpucs uuuuuuuu 4 port configs uuuuuuuu 5 port registers uuuuuuuu 6 port oes uuuuuuuu 7 interrupt enables uuuuuuuu 8 interrupt reqs uuuuuuuu 9 bulk in c/s 00000000 unarm 10 bulk out c/s uuuuuuuu retain armed/unarmed state 11 toggle bits 00000000 12 usbcs uuuuuuuu renum bit unchanged 13 fnaddr 00000000 usb function address 14 in07val uuuuuuuu 15 out07val uuuuuuuu 16 inisoval uuuuuuuu 17 outisoval uuuuuuuu 18 usbpair uuuuuuuu 19 configuration 0 20 alternate setting 0
chapter 10. ez-usb resets page 10-7 it as stale simply by not reading it. in either case, the 8051 loads a dummy value to the endpoint byte count register to re-arm out transfers. ? toggle bits are cleared (11). ? the device address is reset to zero (13). note from item 12 that the renum bit is unchanged after a usb bus reset. therefore, if a device has renumerated ? and loaded a new personality, it retains the new personality through a usb bus reset. 10.6 ez-usb disconnect although not strictly a ?reset,? when the ez-usb simulates a disconnect-reconnect in order to renumerate ? , there are effects on the ez-usb core: ? bulk in endpoints are unarmed, and bulk out endpoints are armed (9-10). table 10-3. effects of an ez-usb disconnect and re-connect item register default value comment 1 endpt data uuuuuuuu u = unchanged 2 byte counts uuuuuuuu 3 cpucs uuuuuuuu 4 port configs uuuuuuuu 5 port registers uuuuuuuu 6 port oes uuuuuuuu 7 interrupt enables uuuuuuuu 8 interrupt reqs uuuuuuuu 9 bulk in c/s 00000000 unarm, clear stall bit 10 bulk out c/s 00000000 arm, clear stall bit 11 toggle bits 00000000 reset 12 usbcs uuuuuuuu renum bit unchanged 13 fnaddr 00000000 usb function address 14 in07val uuuuuuuu 15 out07val uuuuuuuu 16 inisoval uuuuuuuu 17 outisoval uuuuuuuu 18 usbpair uuuuuuuu 19 configuration 0 20 alternate setting 0
ez-usb technical reference manual page 10-8 ez-usb technical reference manual v1.10 ? endpoint stall bits are cleared (9-10). ? data toggles are reset (11). ? the function address is reset to zero (13). ? the configuration is reset to zero (19). ? alternate settings are reset to zero (20). 10.7 reset summary table 10-4 summarizes the effects of the four ez-usb resets. table 10-4. effects of various ez-usb resets (?u? means ?unaffected?) resource reset pin usb bus reset disconnect 8051 reset 8051 reset reset u u n/a ep0-7 in eps unarm unarm unarm unarm ep0-7 out eps unarm u arm unarm/arm breakpoint reset u u reset stall bits reset u reset u interrupt enables reset u u reset interrupt reqs reset u u u clk24 run u u u data toggles reset reset reset u function address reset reset reset u configuration 0 0 0 u renum 0 u u u note the i 2 c controller is not reset for any of the conditions laid out in table 10-4. only the ez-usb reset pin resets it.
chapter 11. ez-usb power management page 11-1 chapter 11 ez-usb power management 11.1 introduction the usb host can suspend a device to put it into a power-down mode. when the usb signals a suspend operation, the ez-usb chip goes through a sequence of steps to allow the 8051 to first turn off external power-consuming subsystems, and then enter an ultra-low-power mode by turning off its oscillator. once suspended, the ez-usb chip is awakened either by resumption of usb bus activity, or by assertion of its wakeup# pin. this chapter describes the suspend-resume mecha- nism. figure 11-1. suspend-resume control pll oscillator div by 2 8051 48 mhz clk24 12 mhz start usb resume wakeup pin pcon.0 stop usb "suspend" interrupt no usb activity for 3 msec. resume int signal resume (usbcs.0) restart delay
ez-usb technical reference manual page 11-2 ez-usb technical reference manual v1.10 figure 11-1 illustrates the ez-usb logic that implements usb suspend and resume. these oper- ations are explained in the next sections. 11.2 suspend figure 11-2. ez-usb suspend sequence a usb device recognizes suspend as 3 ms of a bus idle (?j?) state. the ez-usb core alerts the 8051 by asserting the usb (int2) interrupt and the suspend interrupt vector. this gives the 8051 code a chance to perform power conservation housekeeping before shutting down the oscil- lator. pll oscillator div by 2 8051 48 mhz clk24 12 mhz stop usb "suspend" interrupt no usb activity for 3 msec. int2 pcon.0
chapter 11. ez-usb power management page 11-3 the 8051 code responds to the suspend interrupt by taking the following steps: 1. performs any necessary housekeeping such as shutting off external power-consuming devices. 2. sets bit 0 of the pcon sfr (special function register). this has two effects: ? the 8051 enters its idle mode, which is exited by any interrupt. ? the 8051 sends an internal signal to the ez-usb core which causes it to turn off the oscillator and pll. these actions put the ez-usb chip into a low-power mode, as required by the usb specification. 11.3 resume figure 11-3. ez-usb resume sequence pll oscillator div by 2 8051 48 mhz clk24 12 mhz start usb resume wakeup# pin resume int signal resume (usbcs.0) restart delay
ez-usb technical reference manual page 11-4 ez-usb technical reference manual v1.10 the ez-usb oscillator re-starts when: ? usb bus activity resumes (shown as ?usb resume? in figure 11-3), or ? external logic asserts the ez-usb wakeup# pin low. after an oscillator stabilization time, the ez-usb core asserts the 8051 resume interrupt (figure 9-1). this causes the 8051 to exit its idle mode. the resume interrupt is the highest pri- ority 8051 interrupt. it is always enabled, unaffected by the ea bit. the resume isr clears the interrupt request flag, and executes an ?reti? (return from interrupt) instruction. this causes the 8051 to continue program execution at the instruction following the one that set pcon.0 to initiate the suspend operation. 11.4 remote wakeup figure 11-4. usb control and status register two bits in the usbcs register are used for remote wakeup, wakesrc and sigrsume. after exiting the idle state, the 8051 reads the wakesrc bit in the usbcs register to discover how the wakeup was initiated. wakesrc=1 indicates assertion of the wakeup# pin, and wakesrc=0 indicates a resumption of usb bus activity. the 8051 clears the wakesrc bit by writing a ?1? to it. about the ?resume? interrupt the 8051 enters the idle mode when pcon.0 is set to ?1.? although the 8051 exits its idle state when any interrupt occurs, the ez-usb logic supports only the resume interrupt for the usb resume operation. this is because the ez-usb core asserts this particular interrupt after restart- ing the 8051 clock. usbcs usb control and status 7fd6 b7 b6 b5 b4 b3 b2 b1 b0 wakesrc - - - discon discoe renum sigrsume note if your design does not use remote wakeup, tie the wakeup# pin high. holding the wakeup# pin low inhibits the ez-usb chip from suspending.
chapter 11. ez-usb power management page 11-5 when a usb device is suspended, the hub driver is tri-stated, and the bus pullup and pulldown resistors cause the bus to assume the ?j,? or idle state. a suspended device signals a remote wakeup by asserting the ?k? state for 10-15 ms. the 8051 controls this using the sigrsume bit in the usbcs register. if the 8051 finds wakesrc=1 after exiting the idle mode, it drives the ?k? state for 10-15 ms to signal the usb remote wakeup. it does this by setting sigrsume=1, waiting 10-15 ms, and then setting sigrsume=0. when sigrsume=0, the ez-usb bus buffer reverts to normal operation. the resume routine should also write a ?1? to the wakesrc bit to clear it. the usb default device does not support remote wakeup. this fact is reported at enumeration time in byte 7 of the built-in configuration descriptor (table 5-10). j and k states the usb specification uses differential data signals d+ and d-. instead of defining a logical ?1? and ?0,? it defines the ?j? and ?k? states. for a high speed device, the ?j? state means (d+ > d-). remote wakeup: the big picture additional factors besides the ez-usb suspend-resume mechanism described in this section determine whether remote wakeup is possible. these are: 1. the device must report that it is capable of signaling a remote wakeup in the ?battributes? field of its configuration descriptor. see table 5-10 for an example of this descriptor. 2. the host must issue a ?set_feature/device? request with the feature selector field set to 0x01 to enable remote wakeup. see table 7-6 for the detailed request.
ez-usb technical reference manual page 11-6 ez-usb technical reference manual v1.10
chapter 12. ez-usb registers page 12-1 chapter 12 ez-usb registers 12.1 introduction this section describes the ez-usb registers in the order they appear in the ez-usb memory map. the registers are named according to the following conventions. most registers deal with endpoints. the general register format is dddnfff, where: ddd is endpoint direction, in or out with respect to the usb host. n is the endpoint number, where: ? ?07? refers to endpoints 0-7 as a group. ? 0-7 refers to each individual bulk/interrupt/control endpoint. ? ?iso? indicates isochronous endpoints as a group. fff is the function, where: ? cs is a control and status register ? irq is an interrupt request bit ? ie is an interrupt enable bit ? bc, bcl, and bch are byte count registers. bc is used for single byte counts, and bcl/h are used as the low and high bytes of 16-bit byte counts. ? data is a single-register access to a fifo. ? buf is the start address of a buffer. examples: ? in7bc is the endpoint 7 in byte count. ? out07irq is the register containing interrupt request bits for out endpoints 0-7.
ez-usb technical reference manual page 12-2 ez-usb technical reference manual v1.10 ? inisoval contains valid bits for the isochronous in endpoints (ep8in-ep15in). figure 12-1. register description format figure 12-1 illustrates the register description format used in this chapter. ? the top line shows the register name, functional description, and address in the ez-usb memory. ? the second line shows the bit position in the register. ? the third line shows the name of each bit in the register. ? the fourth line shows 8051 accessibility: r(ead), w(rite), or r/w. ? the fifth line shows the default value. these values apply after a power-on-reset (por). other conventions usb indicates a global (not endpoint-specific) usb function. addr is an address. val means ?valid.? frame is a frame count. ptr is an address pointer. register name register function address b7 b6 b5 b4 b3 b2 b1 b0 bitname bitname bitname bitname bitname bitname bitname bitname r, w access r, w access r, w access r, w access r, w access r, w access r, w access r, w access default val default val default val default val default val default val default val default val
chapter 12. ez-usb registers page 12-3 12.2 bulk data buffers * see table 12-1 for individual endpoint buffer addresses. figure 12-2. bulk data buffers sixteen 64-byte bulk data buffers appear at 0x1b40 and 0x7b40 in the 8k version of ez-usb, and only at 0x7b40 in the 32k version of ez-usb. the endpoints are ordered to permit the reuse of the buffer space as contiguous ram when the higher numbered endpoints are not used. these registers default to unknown states. innbuf,outnbuf endpoint 0-7 in/out data buffers 1b40-1f3f* b7 b6 b5 b4 b3 b2 b1 b0 d7 d6 d5 d4 d3 d2 d1 d0 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x table 12-1. bulk endpoint buffer memory addresses address address name size 1f00-1f3f 7f00-7f3f in0buf 64 1ec0-1eff 7ec0-7eff out0buf 64 1e80-1ebf 7e80-7ebf in1buf 64 1e40-1e7f 7e40-7e7f out1buf 64 1e00-1e3f 7e00-7e3f in2buf 64 1dc0-1dff 7dc0-7dff out2buf 64 1d80-1dbf 7d80-7dbf in3buf 64 1d40-1d7f 7d40-7d7f out3buf 64 1d00-1d3f 7d00-7d3f in4buf 64 1cc0-1cff 7cc0-7cff out4buf 64 1c80-1cbf 7c80-7cbf in5buf 64 1c40-1c7f 7c40-7c7f out5buf 64 1c00-1c3f 7c00-7c3f in6buf 64 1bc0-1bff 7bc0-7bff out6buf 64 1b80-1bbf 7b80-7bbf in7buf 64 1b40-1b7f 7b40-7b7f out7buf 64
ez-usb technical reference manual page 12-4 ez-usb technical reference manual v1.10 12.3 isochronous data fifos * see table 12-2 for individual endpoint buffer addresses. figure 12-3. isochronous data fifos sixteen addressable data registers hold data from the eight isochronous in endpoints and the eight isochronous out endpoints. reading a data register reads a receive fifo byte (usb out data); writing a data register loads a transmit fifo byte (usb in data). outndata ep8out-ep15out fifo registers 7f60-7f67* b7 b6 b5 b4 b3 b2 b1 b0 d7 d6 d5 d4 d3 d2 d1 d0 r r r r r r r r x x x x x x x x inndata ep8in-ep15in fifo registers 7f68-7f6f* b7 b6 b5 b4 b3 b2 b1 b0 d7 d6 d5 d4 d3 d2 d1 d0 w w w w w w w w x x x x x x x x table 12-2. isochronous endpoint fifo register addresses address isochronous data name 7f60 endpoint 8 out data out8data 7f61 endpoint 9 out data out9data 7f62 endpoint 10 out data out10data 7f63 endpoint 11 out data out11data 7f64 endpoint 12 out data out12data 7f65 endpoint 13 out data out13data 7f66 endpoint 14 out data out14data 7f67 endpoint 15 out data out15data 7f68 endpoint 8 in data in8data 7f69 endpoint 9 in data in9data 7f6a endpoint 10 in data in10data 7f6b endpoint 11 in data in11data 7f6c endpoint 12 in data in12data 7f6d endpoint 13 in data in13data 7f6e endpoint 14 in data in14data 7f6f endpoint 15 in data in15data
chapter 12. ez-usb registers page 12-5 12.4 isochronous byte counts * see table 12-3 for individual endpoint buffer addresses. figure 12-4. isochronous byte counts outnbch out(8-15) byte count high 7f70-7f7f* b7 b6 b5 b4 b3 b2 b1 b0 0 0 0 0 0 0 bc9 bc8 r r r r r r r r x x x x x x x x outnbcl out(8-15) byte count low 7f70-7f7f* b7 b6 b5 b4 b3 b2 b1 b0 bc7 bc6 bc5 bc4 bc3 bc2 bc1 bc0 r r r r r r r r x x x x x x x x table 12-3. isochronous endpoint byte count register addresses address isochronous data name 7f70 endpoint 8 byte count high out8bch 7f71 endpoint 8 byte count low out8bcl 7f72 endpoint 9 byte count high out9bch 7f73 endpoint 9 byte count low out9bcl 7f74 endpoint 10 byte count high out10bch 7f75 endpoint 10 byte count low out10bcl 7f76 endpoint 11 byte count high out11bch 7f77 endpoint 11 byte count low out11bcl 7f78 endpoint 12 byte count high out12bch 7f79 endpoint 12 byte count low out12bcl 7f7a endpoint 13 byte count high out13bch 7f7b endpoint 13 byte count low out13bcl 7f7c endpoint 14 byte count high out14bch 7f7d endpoint 14 byte count low out14bcl 7f7e endpoint 15 byte count high out15bch 7f7f endpoint 15 byte count low out15bcl
ez-usb technical reference manual page 12-6 ez-usb technical reference manual v1.10 the ez-usb core uses the byte count registers to report isochronous data payload sizes for out data transferred from the host to the usb core. ten bits of byte count data allow payload sizes up to 1,023 bytes. a byte count of zero is valid, meaning that the host sent no isochronous data dur- ing the previous frame. the default values of these registers are unknown. byte counts are valid only for out endpoints. the byte counts indicate the number of bytes remaining in the endpoint?s receive fifo. every time the 8051 reads a byte from the isodata register, the byte count decrements by one. to read usb out data, the 8051 first reads byte count registers outnbcl and outnbch to determine how many bytes to transfer out of the out fifo. (the 8051 can also quickly test iso output endpoints for zero byte counts using the zbcout register.) then, the cpu reads that number of bytes from the isodata register. separate byte counts are maintained for each end- point, so the cpu can read the fifos in a discontinuous manner. for example, if ep8 indicates a byte count of 100, and ep9 indicates a byte count of 50, the cpu could read 50 bytes from ep8, then read 10 bytes from ep9, and resume reading ep8. at this moment the byte count for ep8 would read 50. there are no byte count registers for the in endpoints. the usb core automatically tracks the number of bytes loaded by the 8051. if the 8051 does not load an in isochronous endpoint fifo during a 1-ms frame, and the host requests data from that endpoint during the next frame (in token), the usb core responds accord- ing to the setting of the isosend0 bit (usbpair.7). if isosend0=1, the core returns a zero- length data packet in response to the host in token. if isosend=0, the core does not respond to the in token. it is the responsibility of the 8051 programmer to ensure that the number of bytes written to the in fifo does not exceed the maximum packet size as reported during enumeration. 12.5 cpu registers figure 12-5. cpu control and status register this register enables the clk24 output and permits the host to reset the 8051 using a firmware download. cpucs cpu control and status 7f92 b7 b6 b5 b4 b3 b2 b1 b0 rv3 rv2 rv1 rv0 0 0 clk24oe 8051res r r r r r r r/w r rv3 rv2 rv1 rv0 0 0 1 1
chapter 12. ez-usb registers page 12-7 bit 7-4: rv[3..0] silicon revision these register bits define the silicon revision. consult individual cypress semiconductor data sheets for values. bit 1: clk24oe output enable - clk24 pin when this bit is set to 1, the internal 24-mhz clock is connected to the ez-usb clk24 pin. when this bit is 0, the clk24 pin drives hi. this bit can be written by the 8051 only. bit 0: 8051res 8051 reset the usb host writes ?1? to this bit to reset the 8051, and ?0? to run the 8051. only the usb host can write this bit. 12.6 port configuration figure 12-6. io port configuration registers portacfg io port a configuration 7f93 b7 b6 b5 b4 b3 b2 b1 b0 rxd1out rxd0out frd fwr cs oe t1out t0out r/w r/w r/w r/w r/w r/w r/w r/w 0 0 0 0 0 0 0 0 portbcfg io port b configuration 7f94 b7 b6 b5 b4 b3 b2 b1 b0 t2out int6 int5 int4 txd1 rxd1 t2ex t2 r/w r/w r/w r/w r/w r/w r/w r/w 0 0 0 0 0 0 0 0 portccfg io port c configuration 7f95 b7 b6 b5 b4 b3 b2 b1 b0 rd wr t1 t0 int1 int0 txd0 rxd0 r/w r/w r/w r/w r/w r/w r/w r/w 0 0 0 0 0 0 0 0
ez-usb technical reference manual page 12-8 ez-usb technical reference manual v1.10 these three registers control the three io ports on the ez-usb chip. they select between io ports and various alternate functions. they are read/write by the 8051. when portncfg=0, the port pin functions as io, using the out, pins, and oe control bits. data written to an outn registers appears on an io port pin if the corresponding output enable bit (oen) is hi. when portncfg=1, the pin assumes the alternate function shown in table 12-4 on the following page. table 12-4. io pin alternate functions i/o name alternate functions pa0 t0out timer 0 output pa1 t1out timer 1 output pa2 oe# external memory output enable pa3 cs# external memory chip select pa4 fwr# fast access write strobe pa5 frd# fast access read strobe pa6 rxd0out mode 0: uart0 synchronous data output pa7 rxd1out mode 0: uart1 synchronous data output pb0 t2 timer/counter 2 clock input pb1 t2ex timer/counter 2 capture/reload input pb2 rxd1 serial port 1 input pb3 txd1 mode 0: clock output modes 1-3: serial port 1 data output pb4 int4 int4 interrupt request pb5 int5# int5 interrupt request pb6 int6 int6 interrupt request pb7 t2out timer/counter 2 overflow indication pc0 rxd0 serial port 0 input pc1 txd0 mode 0: clock output modes 1-3: serial port 0 data output pc2 int0# int0 interrupt request pc3 int1# int1 interrupt request pc4 t0 timer/counter 0 external input pc5 t1 timer/counter 1 external input pc6 wr# external memory write strobe pc7 rd# external memory read strobe
chapter 12. ez-usb registers page 12-9 12.7 input-output port registers figure 12-7. output port configuration registers the outn registers provide the data that drives the port pin when oe=1 and the portncfg pin is 0. if the port pin is selected a an input (oe=0), the value stored in the corresponding outn bit is stored in an output latch but not used. outa port a outputs 7f96 b7 b6 b5 b4 b3 b2 b1 b0 outa7 outa6 outa5 outa4 outa3 outa2 outa1 outa0 r/w r/w r/w r/w r/w r/w r/w r/w 0 0 0 0 0 0 0 0 outb port b outputs 7f97 b7 b6 b5 b4 b3 b2 b1 b0 outb7 outb6 outb5 outb4 outb3 outb2 outb1 outb0 r/w r/w r/w r/w r/w r/w r/w r/w 0 0 0 0 0 0 0 0 outc port c outputs 7f98 b7 b6 b5 b4 b3 b2 b1 b0 outc7 outc6 outc5 outc4 outc3 outc2 outc1 outc0 r/w r/w r/w r/w r/w r/w r/w r/w 0 0 0 0 0 0 0 0
ez-usb technical reference manual page 12-10 ez-usb technical reference manual v1.10 figure 12-8. pinsn registers the pinsn registers contain the current value of the port pins, whether they are selected as io ports or alternate functions. pinsa port a pins 7f99 b7 b6 b5 b4 b3 b2 b1 b0 pina7 pina6 pina5 pina4 pina3 pina2 pina1 pina0 r r r r r r r r x x x x x x x x pinsb port b pins 7f9a b7 b6 b5 b4 b3 b2 b1 b0 pinb7 pinb6 pinb5 pinb4 pinb3 pinb2 pinb1 pinb0 r r r r r r r r x x x x x x x x pinsc port c pins 7f9b b7 b6 b5 b4 b3 b2 b1 b0 pinc7 pinc6 pinc5 pinc4 pinc3 pinc2 pinc1 pinc0 r r r r r r r r x x x x x x x x
chapter 12. ez-usb registers page 12-11 figure 12-9. output enable registers the oe registers control the output enables on the tri-state drivers connected to the port pins. when these bits are ?1,? the port is an output, unless the corresponding portncfg bit is set to a ?1.? 12.8 isochronous control/status registers figure 12-10. isochronous out endpoint error register oea port a output enable 7f9c b7 b6 b5 b4 b3 b2 b1 b0 oea7 oea6 oea5 oea4 oea3 oea2 oea1 oea0 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x oeb port b output enable 7f9d b7 b6 b5 b4 b3 b2 b1 b0 oeb7 oeb6 oeb5 oeb4 oeb3 oeb2 oeb1 oeb0 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x oec port c output enable 7f9e b7 b6 b5 b4 b3 b2 b1 b0 oec7 oec6 oec5 oec4 oec3 oec2 oec1 oec0 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x isoerr isochronous out ep error 7fa0 b7 b6 b5 b4 b3 b2 b1 b0 iso15err iso14err iso13err iso12err iso11err iso10err iso9err iso8err r r r r r r r r x x x x x x x x
ez-usb technical reference manual page 12-12 ez-usb technical reference manual v1.10 the isoerr bits are updated at every sof. they indicate that a crc error was received on a data packet for the current frame. the isoerr bit status refers to the usb data received in the previous frame, and which is currently in the endpoint?s out fifo. if the isoerr bit = 1, indicat- ing a bad crc check, the data is still available in the outndata register. figure 12-11. isochronous control register bit 3: ppstat ping-pong status this bit indicates the isochronous buffer currently in use by the ez-usb core. it is used only for diagnostic purposes. bits 2,1: mbz must be zero these bits must always be written with zeros. bit 0: isodisab iso endpoints disable isodisab=0 enables all 16 isochronous endpoints isodisab=1 disables all 16 isochronous endpoints, making the 2,048 bytes of isochronous fifo memory available as 8051 data memory at 0x2000-0x27ff. figure 12-12. zero byte count register bits 0-7: ep(n) zero byte count for iso out endpoints the 8051 can check these bits as a fast way to check all of the out isochronous endpoints at once for no data received during the previous frame. a ?1? in any bit position means that a zero byte isochronous out packet was received for the indicated endpoint. isoctl isochronous control 7fa1 b7 b6 b5 b4 b3 b2 b1 b0 - - - - ppstat mbz mbz isodisab r r r r r r/w r/w r/w 0 0 0 0 0 0 0 0 zbcout zero byte count bits 7fa2 b7 b6 b5 b4 b3 b2 b1 b0 ep15 ep14 ep13 ep12 ep11 ep10 ep9 ep8 r r r r r r r r x x x x x x x x
chapter 12. ez-usb registers page 12-13 12.9 i 2 c registers figure 12-13. i 2 c transfer registers the 8051 uses these registers to transfer data over the ez-usb i 2 c bus. bit 7: start signal start condition the 8051 sets the start bit to ?1? to prepare an i 2 c bus transfer. if start=1, the next 8051 load to i2dat will generate the start condition followed by the serialized byte of data in i2dat. the 8051 loads byte data into i2dat after setting the start bit. the i 2 c controller clears the start bit during the ack interval. bit 6: stop signal stop condition the 8051 sets stop=1 to terminate an i 2 c bus transfer. the i 2 c controller clears the stop bit after completing the stop condition. if the 8051 sets the stop bit during a byte transfer, the stop condition will be generated immediately following the ack phase of the byte trans- fer. if no byte transfer is occurring when the stop bit is set, the stop condition will be carried out immediately on the bus. data should not be written to i2cs or i2dat until the stop bit returns low. bit 5: lastrd last data read to read data over the i 2 c bus, an i 2 c master floats the sda line and issues clock pulses on the scl line. after every eight bits, the master drives sda low for one clock to indicate ack. to signal the last byte of the read transfer, the master floats sda at ack time to instruct the slave to stop sending. this is controlled by the 8051 by setting lastrd=1 before reading the i2cs i 2 c control and status 7fa5 b7 b6 b5 b4 b3 b2 b1 b0 start stop lastrd id1 id0 berr ack done r/w r/w r/w r r r r r 0 0 0 x x 0 0 0 i2dat i 2 c data 7fa6 b7 b6 b5 b4 b3 b2 b1 b0 d7 d6 d5 d4 d3 d2 d1 d0 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x
ez-usb technical reference manual page 12-14 ez-usb technical reference manual v1.10 last byte of a read transfer. the i 2 c controller clears the lastrd bit at the end of the transfer (at ack time). bit 4-3: id1, id0 boot eeprom id these bits are set by the boot loader to indicate whether an 8-bit address or 16-bit address eeprom at slave address 000 or 001 was detected at power-on. normally, they are used for debug purposes only. bit 2: berr bus error this bit indicates an i 2 c bus error. berr=1 indicates that there was bus contention, which results when an outside device drives the bus lo when it shouldn?t, or when another bus mas- ter wins arbitration, taking control of the bus. berr is cleared when 8051 reads or writes the idata register. bit 1: ack acknowledge bit every ninth scl or a write transfer the slave indicates reception of the byte by asserting ack. the ez-usb controller floats sda during this time, samples the sda line, and updates the ack bit with the complement of the detected value. ack=1 indicates acknowledge, and ack=0 indicates not-acknowledge. the ez-usb core updates the ack bit at the same time it sets done=1. the ack bit should be ignored for read transfers on the bus. bit 0: done i 2 c transfer done the i 2 c controller sets this bit whenever it completes a byte transfer, right after the ack stage. the controller also generates an i 2 c interrupt request (8051 int3) when it sets the done bit. the i 2 c controller automatically clears the done bit and the i 2 c interrupt request bit when- ever the 8051 reads or writes the i2dat register. note setting lastrd does not automatically generate a stop condition. the 8051 should also set the stop bit at the end of a read transfer.
chapter 12. ez-usb registers page 12-15 12.10 interrupts figure 12-14. interrupt vector register ivec indicates the source of an interrupt from the usb core. when the usb core generates an int2 (usb) interrupt request, it updates ivec to indicate the source of the interrupt. the interrupt sources are encoded on iv[4..0] as shown in figure 9-2. figure 12-15. in/out interrupt request (irq) registers these interrupt request (irq) registers indicate the pending interrupts for each bulk endpoint. an interrupt request (ir) bit becomes active when the bsy bit for an endpoint makes a transition from one to zero (the endpoint becomes un-busy , giving access to the 8051). the ir bits function inde- pendently of the interrupt enable (ie) bits, so interrupt requests are held whether or not the inter- rupts are enabled. the 8051 clears an interrupt request bit by writing a ?1? to it (see the following note). ivec interrupt vector 7fa8 b7 b6 b5 b4 b3 b2 b1 b0 0 iv4 iv3 iv2 iv1 iv0 0 0 r r r r r r r r 0 0 0 0 0 0 0 0 in07irq endpoint 0-7 in interrupt request 7fa9 b7 b6 b5 b4 b3 b2 b1 b0 in7ir in6ir in5ir in4ir in3ir in2ir in1ir in0ir r/w r/w r/w r/w r/w r/w r/w r/w 0 0 0 0 0 0 0 0 out07irq endpoint 0-7 out interrupt requests 7faa b7 b6 b5 b4 b3 b2 b1 b0 out7ir out6ir out5ir out4ir out3ir out2ir out1ir out0ir r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x
ez-usb technical reference manual page 12-16 ez-usb technical reference manual v1.10 figure 12-16. usb interrupt request (irq) registers usbirq indicates the interrupt request status of the usb reset, suspend, setup token, start of frame, and setup data available interrupts. bit 4: uresir usb reset interrupt request the ez-usb core sets this bit to ?1? when it detects a usb bus reset. because this bit can change state while the 8051 is in reset, it may be active when the 8051 comes out of reset, although it is reset to ?0? by a power-on reset. write a ?1? to this bit to clear the interrupt request. see chapter 10, "ez-usb resets" for more information about this bit. bit 3: suspir usb suspend interrupt request the ez-usb core sets this bit to ?1? when it detects usb suspend signaling (no bus activity for 3 ms). write a ?1? to this bit to clear the interrupt request. because this bit can change state while the 8051 is in reset, it may be active when the 8051 comes out of reset, although it is reset to ?0? by a power-on reset. see chapter 11, "ez-usb power management" for more information about this bit. bit 2: sutokir setup token interrupt request the ez-usb core sets this bit to ?1? when it receives a setup token. write a ?1? to this bit to clear the interrupt request. see chapter 7, "ez-usb endpoint zero" for more information on the handling of setup tokens. because this bit can change state while the 8051 is in reset, it may be active when the 8051 comes out of reset, although it is reset to ?0? by a power-on reset. note do not clear an irq bit by reading an irq register, oring its contents with a bit mask, and writ- ing back the irq register. this will clear all pending interrupts. instead, simply write the bit mask value (with the irq you want to clear) directly to the irq register. usbirq usb interrupt request 7fab b7 b6 b5 b4 b3 b2 b1 b0 - - - uresir suspir sutokir sofir sudavir r/w r/w r/w r/w r/w r/w r/w r/w 0 0 0 0 0 0 0 0
chapter 12. ez-usb registers page 12-17 bit 1: sofir start of frame interrupt request the ez-usb core sets this bit to ?1? when it receives a sof packet. write a ?1? to this bit to clear the interrupt condition. because this bit can change state while the 8051 is in reset, it may be active when the 8051 comes out of reset, although it is reset to ?0? by a power-on reset. bit 0: sudavir setup data available interrupt request the ez-usb core sets this bit to ?1? when it has transferred the eight data bytes from an end- point zero setup packet into internal registers (at setupdat). write a ?1? to this bit to clear the interrupt condition. because this bit can change state while the 8051 is in reset, it may be active when the 8051 comes out of reset, although it is reset to ?0? by a power-on reset. figure 12-17. in/out interrupt enable registers the endpoint interrupt enable registers define which endpoints have active interrupts. they do not affect the endpoint action, only the generation of an interrupt in response to endpoint events. when the ien bit for an endpoint is ?0,? the interrupt request bit for that endpoint is ignored, but saved. when the ien bit for an endpoint is ?1,? any irq bit equal to ?1? generates an 8051 int2 request. in07en endpoint 0-7 in interrupt enables 7fac b7 b6 b5 b4 b3 b2 b1 b0 in7ien in6ien in5ien in4ien in3ien in2ien in1ien in0ien r/w r/w r/w r/w r/w r/w r/w r/w 0 0 0 0 0 0 0 0 out07ien endpoint 0-7 out interrupt enables 7fad b7 b6 b5 b4 b3 b2 b1 b0 out7ien out6ien out5ien out4ien out3ien out2ien out1ien out0ien r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x
ez-usb technical reference manual page 12-18 ez-usb technical reference manual v1.10 figure 12-18. usb interrupt enable register usbien bits gate the interrupt request to the 8051 for usb reset, suspend, setup token, start of frame, and setup data available. bit 4: uresie usb reset interrupt enable this bit is the interrupt mask for the uresir bit. when this bit is ?1,? the interrupt is enabled, when it is ?0,? the interrupt is disabled. bit 3: suspie usb suspend interrupt enable this bit is the interrupt mask for the suspir bit. when this bit is ?1,? the interrupt is enabled, when it is ?0,? the interrupt is disabled. bit 2: sutokie setup token interrupt enable this bit is the interrupt mask for the sutokir bit. when this bit is ?1,? the interrupt is enabled, when it is ?0,? the interrupt is disabled. bit 1: sofie start of frame interrupt enable this bit is the interrupt mask for the sofie bit. when this bit is ?1,? the interrupt is enabled, when it is ?0,? the interrupt is disabled. bit 0: sudavie setup data available interrupt enable this bit is the interrupt mask for the sudavie bit. when this bit is ?1,? the interrupt is enabled, when it is ?0,? the interrupt is disabled. note the int2 interrupt (eie.0) and the 8051 global interrupt enable (ea) must be enabled for the endpoint interrupts to propagate to the 8051. once the int2 interrupt is active, it must be cleared by software. usbien usb interrupt enable 7fae b7 b6 b5 b4 b3 b2 b1 b0 - - - uresie suspie sutokie sofie sudavie r/w r/w r/w r/w r/w r/w r/w r/w 0 0 0 0 0 0 0 0
chapter 12. ez-usb registers page 12-19 figure 12-19. breakpoint and autovector register bit 3: break breakpoint enable the break bit is set when the 8051 address bus matches the address held in the bit break- point address registers (next page). the bkpt pin reflects the state of this bit. the 8051 writes a ?1? to the break bit to clear it. it is not necessary to clear the break bit if the pulse mode bit (bppulse) is set. bit 2: bppulse breakpoint pulse mode the 8051 sets this bit to ?1? to pulse the break bit (and bkpt pin) high for 8 clk24 cycles when the 8051 address bus matches the address held in the breakpoint address registers. when this bit is set to ?0,? the break bit (and bkpt pin) remains high until it is cleared by the 8051. bit 1: bpen breakpoint enable if this bit is ?1,? a break signal is generated whenever the 16-bit address lines match the value in the breakpoint address registers (bpaddrh/l). the behavior of the break bit and associated bkpt pin signal is either latched or pulsed, depending on the state of the bppulse bit. bit 0: aven auto-vector enable if this bit is ?1,? the ez-usb auto-vector feature is enabled. if it is 0, the auto-vector feature is disabled. see chapter 9, "ez-usb interrupts" for more information on the auto-vector feature. figure 12-20. in bulk nak interrupt request register usbbav breakpoint and autovector 7faf b7 b6 b5 b4 b3 b2 b1 b0 - - - - break bppulse bpen aven r/w r/w r/w r/w r/w r/w r/w r/w 0 0 0 0 0 0 0 0 ibnirq in bulk nak interrupt requests 7fb0 b7 b6 b5 b4 b3 b2 b1 b0 - ep6in ep5in ep4in ep3in ep2in ep1in ep0in r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x
ez-usb technical reference manual page 12-20 ez-usb technical reference manual v1.10 these bits are set when a bulk in endpoint (0-6) received an in token while the endpoint was not armed for data transfer. in this case the sie automatically sends a nak response, and sets the corresponding ibnirq bit. if the ibn interrupt is enabled (usbien.5=1), and the endpoint inter- rupt is enabled in the ibnien register, an interrupt is request generated. the 8051 can test the ibnirq register to determine which of the endpoints caused the interrupt. the 8051 clears an ibnirq bit by writing a ?1? to it. figure 12-21. in bulk nak interrupt enable register each of the individual in endpoints may be enabled for an ibn interrupt using the ibnen register. the 8051 sets an interrupt enable bit to 1 to enable the corresponding interrupt. figure 12-22. in/out interrupt enable registers when the current 16-bit address (code or xdata) matches the bpaddrh/bpaddrl address, a breakpoint event occurs. the bppulse and bpen bits in the usbbav register control the action taken on a breakpoint event. ibnien in bulk nak interrupt enables 7fb1 b7 b6 b5 b4 b3 b2 b1 b0 - ep6in ep5in ep4in ep3in ep2in ep1in ep0in r/w r/w r/w r/w r/w r/w r/w r/w x x 0 0 0 0 0 0 bpaddrh breakpoint address high 7fb2 b7 b6 b5 b4 b3 b2 b1 b0 a15 a14 a13 a12 a11 a10 a9 a8 r/w r/w r/w r/w r/w r/w r/w r/w 0 0 0 0 0 0 0 0 bpaddrl breakpoint address low 7fb3 b7 b6 b5 b4 b3 b2 b1 b0 a7 a6 a5 a4 a3 a2 a1 a0 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x
chapter 12. ez-usb registers page 12-21 if the bpen bit is ?0,? address breakpoints are ignored. if bpen is ?1? and bppulse is ?1,? an 8 clk24 wide pulse appears on the bkpt pin. if bpen is ?1? and bppulse is ?0,? the bkpt pin remains active until the 8051 clears the break bit by writing ?1? to it. 12.11 endpoint 0 control and status registers figure 12-23. port configuration registers these registers control ez-usb control endpoint zero. because endpoint zero is a bi-direc- tional endpoint, the in and out functionality is controlled by a single control and status (cs) regis- ter, unlike endpoints 1-7, which have separate incs and outcs registers. bit 3: outbsy out endpoint busy outbsy is a read-only bit that is automatically cleared when a setup token arrives. the 8051 sets the outbsy bit by writing a byte count to epoutbc. if the control transfer uses an out data phase, the 8051 must load a dummy byte count into out0bc to arm the out endpoint buffer. until it does, the ez-usb core will nak the out tokens. ep0cs endpoint zero control and status 7fb4 b7 b6 b5 b4 b3 b2 b1 b0 - - - - outbsy inbsy hsnak ep0stall r r r r r r r/w r/w 0 0 0 0 1 0 0 0 in0bc endpoint zero in byte count 7fb5 b7 b6 b5 b4 b3 b2 b1 b0 - bc6 bc5 bc4 bc3 bc2 bc1 bc0 r/w r/w r/w r/w r/w r/w r/w r/w 0 0 0 0 0 0 0 0 out0bc endpoint zero out byte count 7fc5 b7 b6 b5 b4 b3 b2 b1 b0 - bc6 bc5 bc4 bc3 bc2 bc1 bc0 r/w r/w r/w r/w r/w r/w r/w r/w 0 0 0 0 0 0 0 0
ez-usb technical reference manual page 12-22 ez-usb technical reference manual v1.10 bit 2: inbsy in endpoint busy inbsy is a read-only bit that is automatically cleared when a setup token arrives. the 8051 sets the inbsy bit by writing a byte count to in0bc. if the control transfer uses an in data phase, the 8051 loads the requested data into the in0buf buffer, and then loads the byte count into in0bc to arm the data phase of the con- trol transfer. alternatively, the 8051 can arm the data transfer by loading an address into the setup data pointer registers sudptrh/l. until armed, the ez-usb core will nak the in tokens. bit 1: hsnak handshake nak hsnak (handshake nak) is a read/write bit that is automatically set when a setup token arrives. the 8051 clears hsnak by writing a ?1? to the register bit. while hsnak=1, the ez-usb core naks the handshake (status) phase of the control transfer. when hsnak=0, it acks the handshake phase. the 8051 can clear hsnak at any time during a control transfer. bit 0: ep0stall endpoint zero stall ep0stall is a read/write bit that is automatically cleared when a setup token arrives. the 8051 sets ep0stall by writing a ?1? to the register bit. while ep0stall=1, the ez-usb core sends the stall pid for any in or out token. this can occur in either the data or handshake phase of the control transfer. 12.12 endpoint 1-7 control and status registers endpoints 1-7 in and out are used for bulk or interrupt data. table 12-5 shows the addresses for the control/status and byte count registers associated with these endpoints. the bi-directional control endpoint zero registers are described in section 12.11, "endpoint 0 control and status registers." note to indicate an endpoint stall on endpoint zero, set both ep0stall and hsnak bits. setting the ep0stall bit alone causes endpoint zero to nak forever because the host keeps the control transfer pending.
chapter 12. ez-usb registers page 12-23 table 12-5. control and status register addresses for endpoints 0-7 address function name 7fb4 control and status - endpoint in0 ep0cs 7fb5 byte count - endpoint in0 in0bc 7fb6 control and status - endpoint in1 in1cs 7fb7 byte count - endpoint in1 in1bc 7fb8 control and status - endpoint in2 in2cs 7fb9 byte count - endpoint in2 in2bc 7fba control and status - endpoint in3 in3cs 7fbb byte count - endpoint in3 in3bc 7fbc control and status - endpoint in4 in4cs 7fbd byte count - endpoint in4 in4bc 7fbe control and status - endpoint in5 in5cs 7fbf byte count - endpoint in5 in5bc 7fc0 control and status - endpoint in6 in6cs 7fc1 byte count - endpoint in6 in6bc 7fc2 control and status - endpoint in7 in7cs 7fc3 byte count - endpoint in7 in7bc 7fc4 reserved 7fc5 byte count - endpoint out0 out0bc 7fc6 control and status - endpoint out1 out1cs 7fc7 byte count - endpoint out1 out1bc 7fc8 control and status - endpoint out2 out2cs 7fc9 byte count - endpoint out2 out2bc 7fca control and status - endpoint out3 ou37cs 7fcb byte count - endpoint out3 out3bc 7fcc control and status - endpoint out4 out4cs 7fcd byte count - endpoint out4 out4bc 7fce control and status - endpoint out5 out5cs 7fcf byte count - endpoint out5 out5bc 7fd0 control and status - endpoint out6 out6cs 7fd1 byte count - endpoint out6 out6bc 7fd2 control and status - endpoint out7 out7cs 7fd3 byte count - endpoint out7 out7bc
ez-usb technical reference manual page 12-24 ez-usb technical reference manual v1.10 * see table 12-5 for individual control/status register addresses. figure 12-24. in control and status registers bit 1: innbsy in endpoint (1-7) busy the bsy bit indicates the status of the endpoint?s in buffer innbuf. the ez-usb core sets bsy=0 when the endpoint?s in buffer is empty and ready for loading by the 8051. the 8051 sets bsy=1 by loading the endpoint?s byte count register. when bsy=1, the 8051 should not write data to an in endpoint buffer, because the endpoint fifo could be in the act of transferring data to the host over the usb. bsy=0 when the usb in transfer is complete and endpoint ram data is available for 8051 access. usb in tokens for the endpoint are nakd while bsy=0 (the 8051 is still loading data into the endpoint buffer). a 1-to-0 transition of bsy (indicating that the 8051 can access the buffer) generates an inter- rupt request for the in endpoint. after the 8051 writes the data to be transferred to the in end- point buffer, it loads the endpoint?s byte count register with the number of bytes to transfer, which automatically sets bsy=1. this enables the in transfer of data to the host in response to the next in token. again, the cpu should never load endpoint data while bsy=1. the 8051 writes a ?1? to an in endpoint busy bit to disarm a previously armed endpoint. (this sets bsy=0.) the 8051 program should do this only after a usb bus reset, or when the host selects a new interface or alternate setting that uses the endpoint. this prevents stale data from a previous setting from being accepted by the host?s first in transfer that uses the new setting. to disarm a paired in endpoint, write a ?1? to the busy bit for both endpoints in the pair. bit 0: innstl in endpoint (1-7) stall the 8051 sets this bit to ?1? to stall an endpoint, and to ?0? to clear a stall. inncs endpoint (1-7) in control and status 7fb6-7fc2* b7 b6 b5 b4 b3 b2 b1 b0 - - - - - - innbsy innstl r r r r r r r/w r/w 0 0 0 0 0 0 0 0 note: even though the register description shows bit 1 as ?r/w,? the 8051 can only clear this bit by writ- ing a ?1? to it. the 8051 can not directly set this bit.
chapter 12. ez-usb registers page 12-25 when the stall bit is ?1,? the ez-usb core returns a stall handshake for all requests to the endpoint. this notifies the host that something unexpected has happened. the 8051 sets an endpoint?s stall bit under two circumstances: 1. the host sends a ?set_feature?endpoint stall? request to the specific endpoint. 2. the 8051 encounters any show stopper error on the endpoint, and sets the stall bit to tell the host to halt traffic to the endpoint. the 8051 clears an endpoint?s stall bit under two circumstances: 1. the host sends a ?clear_feature--endpoint stall? request to the specific endpoint. 2. the 8051 receives some other indication from the host that the stall should be cleared (this is referred to as ?host intervention? in the usb specification). this indication could be a usb bus reset. all stall bits are automatically cleared when the ez-usb chip renumerates ? by pulsing the discon bit hi. * see table 12-5 for individual byte count register addresses. figure 12-25. in byte count registers the 8051 writes this register with the number of bytes it loaded into the in endpoint buffer innbuf. writing this register also arms the endpoint by setting the endpoint bsy bit to 1. legal values for these registers are 0-64. a zero transfer size is used to terminate a transfer that is an integral multiple of maxpacketsize. for example, a 256-byte transfer with maxpacketsize = 64, would require four packets of 64 bytes each plus one packet of 0 bytes. the in byte count should never be written while the endpoint?s busy bit is set. when the register pairing feature is used (chapter 6, "ez-usb bulk transfers") in2bc is used for the ep2/ep3 pair, in4bc is used for the ep4/ep5 pair, and in6bc is used for the ep6/ep7 pair. in the paired (double-buffered) mode, after the first write to the even-numbered byte count register, the endpoint bsy bit remains at 0, indicating that only one of the buffers is full, and the other is still empty. the odd numbered byte count register is not used when endpoints are paired. innbc endpoint (1-7) in byte count 7fb7-7fc3* b7 b6 b5 b4 b3 b2 b1 b0 - d6 d5 d4 d3 d2 d1 d0 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x
ez-usb technical reference manual page 12-26 ez-usb technical reference manual v1.10 * see table 12-5 for individual control/status register addresses. figure 12-26. out control and status registers bit 1: outnbsy out endpoint (1-7) busy the bsy bit indicates the status of the endpoint?s out buffer outnbuf. the ez-usb core sets bsy=0 when the host data is available in the out buffer. the 8051 sets bsy=1 by load- ing the endpoint?s byte count register. when bsy=1, endpoint ram data is invalid--the endpoint buffer has been emptied by the 8051 and is waiting for new out data from the host, or it is the process of being loaded over the usb. bsy=0 when the usb out transfer is complete and endpoint ram data in outn- buf is available for the 8051 to read. usb out tokens for the endpoint are nakd while bsy=1 (the 8051 is still reading data from the out endpoint). a 1-to-0 transition of bsy (indicating that the 8051 can access the buffer) generates an inter- rupt request for the out endpoint. after the 8051 reads the data from the out endpoint buffer, it loads the endpoint?s byte count register with any value to re-arm the endpoint, which automatically sets bsy=1. this enables the out transfer of data from the host in response to the next out token. the cpu should never read endpoint data while bsy=1. bit 0: outnstl out endpoint (1-7) stall the 8051 sets this bit to ?1? to stall an endpoint, and to ?0? to clear a stall. when the stall bit is ?1,? the ez-usb core returns a stall handshake for all requests to the endpoint. this notifies the host that something unexpected has happened. the 8051 sets an endpoint?s stall bit under two circumstances: 1. the host sends a ?set_feature?endpoint stall? request to the specific endpoint. 2. the 8051 encounters any show stopper error on the endpoint, and sets the stall bit to tell the host to halt traffic to the endpoint. the 8051 clears an endpoint?s stall bit under two circumstances: 1. the host sends a ?clear_feature?endpoint stall? request to the specific endpoint. 2. the 8051 receives some other indication from the host that the stall should be cleared (this is referred to as ?host intervention? in the usb specification). outncs endpoint (1-7) out control and status 7fc6-7fd2* b7 b6 b5 b4 b3 b2 b1 b0 - - - - - - outnbsy outnstl r r r r r r r r/w 0 0 0 0 0 0 0 0
chapter 12. ez-usb registers page 12-27 all stall bits are automatically cleared when the ez-usb chip renumerates ? . * see table 12-5 for individual control/status register addresses. figure 12-27. out byte count registers the 8051 reads this register to determine the number of bytes sent to an out endpoint. legal sizes are 0 - 64 bytes. each ez-usb bulk out endpoint has a byte count register, which serves two purposes. the 8051 reads the byte count register to determine how many bytes were received during the last out transfer from the host. the 8051 writes the byte count register (with any value) to tell the ez-usb core that it has finished reading bytes from the buffer, making the buffer available to accept the next out transfer. writing the byte count register sets the endpoint?s bsy bit to ?1.? when the register-pairing feature is used, out2bc is used for the ep2/ep3 pair, out4bc is used for the ep4/ep5 pair, and out6bc is used for the ep6/ep7 pair. the odd-numbered byte count registers should not be used. when the 8051 writes a byte to the even numbered byte count reg- ister, the ez-usb core switches buffers. if the other buffer already contains data to be read by the 8051, the outnbsy bit remains at ?0.? all out tokens are nakd until the 8051 is released from reset, whereupon the ack/nak behav- ior is based on pairing. outnbc endpoint (1-7) out byte count 7fc7-7fd3* b7 b6 b5 b4 b3 b2 b1 b0 - d6 d5 d4 d3 d2 d1 d0 r r r r r r r r/w 0 0 0 0 0 0 0 0
ez-usb technical reference manual page 12-28 ez-usb technical reference manual v1.10 12.13 global usb registers figure 12-28. setup data pointer high/low registers when the ez-usb chip receives a ?get_descriptor? request on endpoint zero, it can instruct the ez-usb core to handle the multi-packet in transfer by loading these registers with the address of an internal table containing the descriptor data. the descriptor data tables may be placed in inter- nal program/data ram or in unused endpoint 0-7 ram . the sudptr does not operate with external memory. the sudptr registers should be loaded in high/low order. in addition to loading sudptrl, the 8051 must also clear the hsnak bit in the ep0cs register (by writing a ?1? to it) to complete the control transfer. sudptrh setup data pointer high 7fd4 b7 b6 b5 b4 b3 b2 b1 b0 a15 a14 a13 a12 a11 a10 a9 a8 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x sudptrl setup data pointer low 7fd5 b7 b6 b5 b4 b3 b2 b1 b0 a7 a6 a5 a4 a3 a2 a1 a0 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x note any host request that uses the ez-usb setup data pointer to transfer in data must indicate the number of bytes to transfer in bytes 6 (wlenghthl) and 7 (wlengthh) of the setup packet. these bytes are pre-assigned in the usb specification to be length bytes in all standard device requests such as ?get_descriptor.? if vendor-specific requests are used to transfer large blocks of data using the setup data pointer, they must include this pre-defined length field in bytes 6-7 to tell the ez-usb core how many bytes to transfer using the setup data pointer.
chapter 12. ez-usb registers page 12-29 figure 12-29. usb control and status registers bit 7: wakesrc wakeup source this bit indicates that a high to low transaction was detected on the wakeup# pin. writing a ?1? to this bit resets it to ?0.? bit 3: discon signal a disconnect on the discon# pin the ez-usb discon# pin reflects the complement of this bit. this bit is normally set to 0 so that the action of the discoe bit (below) either floats the discon# pin or drives it hi. bit 2: discoe disconnect output enable discoe controls the output buffer on the discon# pin. when discoe=0, the pin floats, and when discoe=1, it drives to the complement of the discon bit (above). discoe is used in conjunction with the renum bit to perform renumeration ? (chapter 5, "ez-usb enumeration and renumeration?." bit 1: renum renumerate this bit controls which entity, the usb core or the 8051, handles usb device requests. when renum=0, the ez-usb core handles all device requests. when renum=1, the 8051 han- dles all device requests except set_address. the 8051 sets renum=1 during a bus disconnect to transfer usb control to the 8051. the ez-usb core automatically sets renum=1 under two conditions: 1. completion of a ?b2? boot load (chapter 5, "ez-usb enumeration and renumeration?"). 2. when external memory is used (ea=1) and no boot i 2 c eeprom is used (see section 10.3.3, "external rom"). bit 0: sigrsume signal remote device resume the 8051 sets sigrsume=1 to drive the ?k? state onto the usb bus. this should be done only by a device that is capable of remote wakeup, and then only during the suspend state. to signal resume, the 8051 sets sigrsume=1, waits 10-15 ms, then sets sigrsume=0. usbcs usb control and status 7fd6 b7 b6 b5 b4 b3 b2 b1 b0 wakesrc - - - discon discoe renum sigrsume r/w r r r r/w r/w r/w r/w 0 0 0 0 0 1 0 0
ez-usb technical reference manual page 12-30 ez-usb technical reference manual v1.10 figure 12-30. data toggle control register bit 7: q data toggle value q=0 indicates data0 and q=1 indicates data1, for the endpoint selected by the io and ep[2..0] bits. the 8051 writes the endpoint select bits (io and ep[2..0]), before reading this value. bit 6: s set data toggle to data1 after selecting the desired endpoint by writing the endpoint select bits (io and ep[2..0]) the 8051 sets s=1 to set the data toggle to data1. the endpoint selection bits should not be changed while this bit is written. bit 5: r set data toggle to data0 after selecting the desired endpoint by writing the endpoint select bits (io and ep[2..0]) the 8051 sets r=1 to set the data toggle to data0. the endpoint selection bits should not be changed while this bit is written. for advice on when to reset the data toggle, see chapter 7, "ez-usb endpoint zero." bit 4: io select in or out endpoint the 8051 sets this bit to select an endpoint direction prior to setting its r or s bit. io=0 selects an out endpoint, io=1 selects an in endpoint. bit 2-0: ep select endpoint the 8051 sets these bits to select an endpoint prior to setting its r or s bit. valid values are 0- 7 to correspond to bulk endpoints in0-in7 and out0-out7. togctl data toggle control 7fd7 b7 b6 b5 b4 b3 b2 b1 b0 q s r io 0 ep2 ep1 ep0 r r/w r/w r/w r/w r/w r/w r/w x x x x x x x x note at this writing there is no known reason to set an endpoint data toggle to 1. this bit is provided for generality and testing only.
chapter 12. ez-usb registers page 12-31 figure 12-31. usb frame count high/low registers every millisecond the host sends a sof token indicating ?start of frame,? along with an 11-bit incrementing frame count. the ez-usb copies the frame count into these registers at every sof. one use of the frame count is to respond to the usb sync_frame request (chapter 7, "ez-usb endpoint zero"). if the usb core detects a missing or garbled sof, it generates an internal sof and increments usbframel-usbrameh. figure 12-32. function address register during the usb enumeration process, the host sends a device a unique 7-bit address, which the ez-usb core copies into this register. there is normally no reason for the cpu to know its usb device address because the usb core automatically responds only to its assigned address. usbframel usb frame count low 7fd8 b7 b6 b5 b4 b3 b2 b1 b0 fc7 fc6 fc5 fc4 fc3 fc2 fc1 fc0 r r r r r r r r x x x x x x x x usbframeh usb frame count high 7fd9 b7 b6 b5 b4 b3 b2 b1 b0 0 0 0 0 0 fc10 fc9 fc8 r r r r r r r r x x x x x x x x fnaddr function address 7fdb b7 b6 b5 b4 b3 b2 b1 b0 0 fa6 fa5 fa4 fa3 fa2 fa1 fa0 r r r r r r r r x x x x x x x x note during renumeration ? the usb core sets register to 0 to allow the ez-usb chip to respond to the default address 0.
ez-usb technical reference manual page 12-32 ez-usb technical reference manual v1.10 figure 12-33. usb endpoint pairing register bit 7: isosend0 isochronous send zero length data packet the isosend0 bit is used when the ez-usb chip receives an isochronous in token while the in fifo is empty. if isosend0=0 (the default value), the ez-usb core does not respond to the in token. if isosend0=1, the ez-usb core sends a zero-length data packet in response to the in token. which action to take depends on the overall system design. the isosend0 bit applies to all of the isochronous in endpoints, in8buf through in15buf. bit 5-3: prnout pair bulk out endpoints set the endpoint pairing bits (prxout) to ?1? to enable double-buffering of the bulk out end- point buffers. with double buffering enabled, the 8051 can operate on one buffer while another is being transferred over usb. the endpoint busy and interrupt request bits function identically, so the 8051 code requires no code modification to support double buffering. when an endpoint is paired, the 8051 uses only the even-numbered endpoint of the pair. the 8051 should not use the paired odd endpoint?s irq, ien, valid bits or the buffer associated with the odd numbered endpoint. bit 2-0: prnin pair bulk in endpoints set the endpoint pairing bits (prxin) to ?1? to enable double-buffering of the bulk in endpoint buffers. with double buffering enabled, the 8051 can operate on one buffer while another is being transferred over usb. when an endpoint is paired, the 8051 should access only the even-numbered endpoint of the pair. the 8051 should not use the irq, ien, valid bits or the buffer associated with the odd numbered endpoint. usbpair usb endpoint pairing 7fdd b7 b6 b5 b4 b3 b2 b1 b0 isosend0 - pr6out pr4out pr2out pr6in pr4in pr2in r/w r/w r/w r/w r/w r/w r/w r/w 0 x 0 0 0 0 0 0
chapter 12. ez-usb registers page 12-33 figure 12-34. in/out valid bits register the 8051 sets val=1 for any active endpoints, and val=0 for inactive endpoints. these bits instruct the ez-usb core to return a ?no response? if an invalid endpoint is addressed, instead of a nak. the default values of these registers are set to support all endpoints that exist in the default usb device (see table 5-1). figure 12-35. isochronous in/out endpoint valid bits register in07val endpoints 0-7 in valid bits 7fde b7 b6 b5 b4 b3 b2 b1 b0 in7val in6val in5val in4val in3val in2val in1val in0val r/w r/w r/w r/w r/w r/w r/w r/w 0 1 0 1 0 1 1 1 out07val endpoints 0-7 out valid bits 7fdf b7 b6 b5 b4 b3 b2 b1 b0 out7val out6val out5val out4val out3val out2val out1val out0val r/w r/w r/w r/w r/w r/w r/w r/w 0 1 0 1 0 1 0 1 inisoval isochronous in endpoint valid bits 7fe0 b7 b6 b5 b4 b3 b2 b1 b0 in15val in14val in13val in12val in11val in10val in9val in8val r/w r/w r/w r/w r/w r/w r/w r/w 0 0 0 0 0 1 1 1 outisoval isochronous out endpoint valid bits 7fe1 b7 b6 b5 b4 b3 b2 b1 b0 out15val out14val out13val out12val out11val out10val out9val out8val r/w r/w r/w r/w r/w r/w r/w r/w 0 0 0 0 0 1 1 1
ez-usb technical reference manual page 12-34 ez-usb technical reference manual v1.10 the 8051 sets val=1 for active endpoints, and val=0 for inactive endpoints. these bits instruct the ez-usb core to return a ?no response? if an invalid endpoint is addressed. the default values of these registers are set to support all endpoints that exist in the default usb device (see table 5-1). 12.14 fast transfers figure 12-36. fast transfer control register the ez-usb core provides a fast transfer mode that improves the8051 transfer speed between external logic and the isochronous and bulk endpoint buffers. the fastxfr register enables the modes for bulk and/or isochronous transfers, and selects the timing waveforms for the frd# and fwr# signals. bit 7: fiso enable fast iso transfers the 8051 sets fiso=1 to enable fast isochronous transfers for all16 isochronous endpoint fifos. when fiso=0, fast transfers are disabled for all 16 isochronous endpoints. bit 6: fblk enable fast bulk transfers the 8051 sets fblk=1 to enable fast bulk transfers using the autopointer (see section 12.15, "setup data") with bulk endpoints. when fblk=0 fast transfers are disabled for bulk endpoints. bit 5: rpol frd# pulse polarity the 8051 sets rpol=0 for active-low frd# pulses, and rpol=1 for active high frd# pulses. bit 4-3: rmod frd# pulse mode these bits select the phasing and width of the frd# pulse. see figure 8-12. fastxfr fast transfer control 7fe2 b7 b6 b5 b4 b3 b2 b1 b0 fiso fblk rpol rmod1 rmod0 wpol wmod1 wmod0 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x
chapter 12. ez-usb registers page 12-35 bit 2: wpol fwr# pulse polarity the 8051 sets wpol=0 for active-low fwr# pulses, and wpol=1 for active high fwr# pulses. bit 1-0: wmod fwr# pulse mode these bits select the phasing and width of the fwr# pulse. see figure 8-11. figure 12-37. auto pointer registers these registers implement the ez-usb autopointer . autoptrh/l the 8051 loads a 16-bit address into the autoptrh/l registers. subsequent reads or writes to the autodata register increment the 16-bit value in these registers. the loaded address must be in internal ez-usb ram. the 8051 can read these registers to determine the address must be in internal ez-usb ram. the 8051 can read these registers to determine the address of the next byte to be accessed via the autodata register. autoptrh auto pointer address high 7fe3 b7 b6 b5 b4 b3 b2 b1 b0 a15 a14 a13 a12 a11 a10 a9 a8 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x autoptrl auto pointer address low 7fe4 b7 b6 b5 b4 b3 b2 b1 b0 a7 a6 a5 a4 a3 a2 a1 a0 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x autodata auto pointer data 7fe5 b7 b6 b5 b4 b3 b2 b1 b0 d7 d6 d5 d4 d3 d2 d1 d0 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x
ez-usb technical reference manual page 12-36 ez-usb technical reference manual v1.10 autodata 8051 data read or written to the autodata register accesses the memory addressed by the autoptrh/l registers, and increments the address after the read or write. these registers allow fifo access to the bulk endpoint buffers, as well as being useful for internal data movement. chapter 6, "ez-usb bulk transfers" and chapter 8, "ez-usb isochronous transfers" explain how to use the autopointer for fast transfers to and from the ez-usb endpoint buffers. 12.15 setup data figure 12-38. setup data buffer this buffer contains the 8 bytes of setup packet data from the most recently received control transfer. the data in setupbuf is valid when the sudavir (setup data available interrupt request) bit is set. the 8051 responds to the sudav interrupt by reading the setup bytes from this buffer. setupbuf setup data buffer (8 bytes) 7fe8-7fef b7 b6 b5 b4 b3 b2 b1 b0 d7 d6 d5 d4 d3 d2 d1 d0 r r r r r r r r x x x x x x x x
chapter 12. ez-usb registers page 12-37 12.16 isochronous fifo sizes * see table 12-6 for individual start address register addresses. figure 12-39. setup data buffer outnaddr iso out endpoint start address 7ff0-7ff7* b7 b6 b5 b4 b3 b2 b1 b0 a9 a8 a7 a6 a5 a4 0 0 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x innaddr iso in endpoint start address 7ff8-7fff* b7 b6 b5 b4 b3 b2 b1 b0 a9 a8 a7 a6 a5 a4 0 0 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x table 12-6. isochronous fifo start address registers address endpoint start address 7ff0 endpoint 8 out start address 7ff1 endpoint 9 out start address 7ff2 endpoint 10 out start address 7ff3 endpoint 11 out start address 7ff4 endpoint 12 out start address 7ff5 endpoint 13 out start address 7ff6 endpoint 14 out start address 7ff7 endpoint 15 out start address 7ff8 endpoint 8 in start address 7ff9 endpoint 9 in start address 7ffa endpoint 10 in start address 7ffb endpoint 11 in start address 7ffc endpoint 12 in start address 7ffd endpoint 13 in start address 7ffe endpoint 14 in start address 7fff endpoint 15 in start address
ez-usb technical reference manual page 12-38 ez-usb technical reference manual v1.10 ez-usb isochronous endpoints use a pool of 1,024 double-buffered fifo bytes. the 1,024 fifo bytes can be divided between any or all of the isochronous endpoints. the 8051 sets isochronous endpoint fifo sizes by writing starting addresses to these registers, starting with address 0. address bits a3-a0 are internally set to zero, so the minimum fifo size is 16 bytes. see section 8.8, "fast transfer speed" for details about how to set these registers.
chapter 13. ez-usb ac/dc parameters page 13-1 chapter 13 ez-usb ac/dc parameters 13.1 electrical characteristics 13.1.1 absolute maximum ratings storage temperature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . -65 o c to +150 o c ambient temperature under bias . . . . . . . . . . . . . . . . . . . . . . . . . -40 o c to +85 o c supply voltage to ground potential . . . . . . . . . . . . . . . . . . . . . . . . . -0.5v to +4.0v dc input voltage to any pin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . -0.5v to +5.8v 13.1.2 operating conditions ta (ambient temperature under bias) . . . . . . . . . . . . . . . . . . . . . . . 0 o c to +70 o c supply voltage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .+3.0v to +3.6v ground voltage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 0v f osc (oscillator or crystal frequency) . . . . . . . . . . . . . . . . . . . . 12 mhz +/- 0.25% 13.1.3 dc characteristics table 13-1. dc characteristics symbol parameter condition min typ max unit notes v cc supply voltage 3.0 3.6 v v ih input high voltage 2.0 5.25 v v il input low voltage -0.5 0.8 v i i input leakage current 0 < v in < v cc + 10 a current is higher (-70a typical) in the switching range between v il-max and v ih-min v oh output high voltage i out = 1.6 ma 2.4 v v ol output low voltage i out = -1.6 ma 0.4 v c in input pin capacitance 10 pf i susp suspend current 110 a i cc supply current 8051 running, connected to usb 50 ma
ez-usb technical reference manual page 13-2 ez-usb technical reference manual v1.10 13.1.4 ac electrical characteristics specified conditions: capacitive load on all pins = 30 pf 13.1.5 general memory timing 13.1.6 program memory read 13.1.7 data memory read table 13-2. general memory timing symbol parameter min typ max unit notes tcl 1/clk24 frequency 41.66 ns tav delay from clock to valid address 0 10 ns tcd delay from clk24 to cs# 2 15 ns toed delay from clk24 to oe# 2 15 ns twd delay from clk24 to wr# 2 15 ns trd delay from clk24 to rd# 2 15 ns tpd delay from clk24 to psen# 2 15 ns table 13-3. program memory read symbol parameter formula min max unit notes taa1 address access time 3tcl-tav-tdsu1 103 ns tah1 address hold from clk24 tcl+1 42 ns tdsu1 data setup to clk24 12 ns tdh1 data hold from clk24 0 ns table 13-4. data memory read symbol parameter formula min max unit notes taa2 address access time 3tcl-tav-tdsu1 103 ns tah2 address hold from clk24 tcl+1 42 ns tdsu2 data setup to clk24 12 ns tdh2 data hold from clk24 0 ns
chapter 13. ez-usb ac/dc parameters page 13-3 13.1.8 data memory write 13.1.9 fast data write 13.1.10 fast data read table 13-5. data memory write symbol parameter formula min max unit notes tah3 address hold from clk24 tcl+2 43 ns tdv clk24 to data valid 15 ns tdvz clk24 to high impedance tcl+16 57 ns table 13-6. fast data write symbol parameter conditions min max unit notes tcdo clock to data output delay 3 15 ns tcwo clock to fifo write output delay 210ns tpfwd propagation delay difference from fifo write to data out 1ns table 13-7. fast data read symbol parameter conditions min max unit notes tcro clock to fifo read output delay 210ns tdsu4 data setup to rising clk24 12 ns tdh4 data hold from rising clk24 2ns
ez-usb technical reference manual page 13-4 ez-usb technical reference manual v1.10 figure 13-1. external memory timing figure 13-2. program memory read timing clk24 a [15.0] tcl cs# tav tcd tcd oe# toed toed wr# twd twd rd# trd trd psen# tpd tpd clk24 a [15.0] tcl tah1 psen# d [7.0] tdh1 tdsu1 cs# oe# taa1 tav
chapter 13. ez-usb ac/dc parameters page 13-5 figure 13-3. data memory read timing figure 13-4. data memory write timing clk24 a [15.0] tcl tah2 rd# d [7.0] tdh2 tdsu2 cs# oe# taa2 clk24 a [15.0] tcl tah3 cs# d [7.0] tdvz tdv wr#
ez-usb technical reference manual page 13-6 ez-usb technical reference manual v1.10 figure 13-5. fast transfer mode block diagram clk24 d [7:0] fwr# ez-usb an2131q asic 80 pqfp ez-usb fast transfer block diagram fifo clock d [7:0] fifo write stobe frd# fifo read stobe
chapter 13. ez-usb ac/dc parameters page 13-7 figure 13-6. fast transfer read timing [mode 00] figure 13-7. fast transfer write timing [mode 00] clk24 d[7..0] frd#[00] tcl input tdsu4 tdh4 tcro tcro clk24 d[7..0] fwr#[00] tcl output tcdo tcdo tcwo tcwo
ez-usb technical reference manual page 13-8 ez-usb technical reference manual v1.10 figure 13-8. fast transfer read timing [mode 01] figure 13-9. fast transfer write timing [mode 01] clk24 d[7..0] frd#[01] tcl input tdsu4 tdh4 tcro tcro clk24 d[7..0] fwr#[01] tcl output tcdo tcdo tcwo tcwo tpfwd
chapter 13. ez-usb ac/dc parameters page 13-9 figure 13-10. fast transfer read timing [mode 10] figure 13-11. fast transfer write timing [mode 10] clk24 d[7..0] frd#[10] tcl input tdsu4 tdh4 tcro tcro clk24 d[7..0] fwr#[10] tcl output tcdo tcdo tcwo tcwo
ez-usb technical reference manual page 13-10 ez-usb technical reference manual v1.10 figure 13-12. fast transfer read timing [mode 11] figure 13-13. fast transfer write timing [mode 11] clk24 d[7..0] frd#[11] tcl input tdsu4 tdh4 tcro tcro clk24 d[7..0] fwr#[11] tcl output tcdo tcdo tcwo tcwo tpfwd
chapter 14. ez-usb packaging page 14-1 chapter 14 ez-usb packaging 14.1 44-pin pqfp package figure 14-1. 44-pin pqfp package (top view) figure 14-2. 44-pin pqfp package (side view) 1 10.10 9.90 13.45 12.95 8.00 ref 11 33 23 12 22 44 34 0.80 bsc. 2.35 max see lead detail 0.45 0.30
ez-usb technical reference manual page 14-2 ez-usb technical reference manual v1.10 figure 14-3. 44-pin pqfp package (detail view) 0 o ~7 o 0.95 0.65 1.60 typ lead detail: a(s=n/s) 2.10 1.95 0.25 0.10 0.23 0.13
chapter 14. ez-usb packaging page 14-3 14.2 80-pin pqfp package figure 14-4. 80-pin pqfp package (top view) figure 14-5. 80-pin pqfp package (side view) 3.0 3.0 80 pqfp 0.80 1.00 ref 124 25 40 64 41 80 65 0.80 bsc. 24.10 23.70 20.05 19.95 14.05 13.95 18.10 17.70 3.04 max 0.42 0.32 see lead detail
ez-usb technical reference manual page 14-4 ez-usb technical reference manual v1.10 figure 14-6. 80-pin pqfp package (detail view) 0 o ~7 o 1.00 0.80 1.95 + 0.15 detail "a" 2.76 2.66 0.28 0.18 8 places 12 o ref. base plane seating plane 0 o ~10 o 0.25 gage plane
chapter 14. ez-usb packaging page 14-5 14.3 48-pin tqfp package figure 14-7. 48-pin tqfp package (side view) figure 14-8. 48-pin tqfp package (top view) 1.60 max see lead detail 0.27 0.17 all dimensions in millimeters. 1 12 36 25 13 24 48 37 0.50 bsc. 48 tqfp 9.00 bsc. 7.00 bsc. all dimensions in millimeters.
ez-usb technical reference manual page 14-6 ez-usb technical reference manual v1.10 figure 14-9. 48-pin tqfp package (detail view) 0.05 0.15 1.35 1.45 0.08 0.20 0 o min. 0.08 r. min. 0.20 min. r. 0 - 7 o 1.00 ref. 0.45 0.75 seating plane base plane 48-pin lead detail all dimensions in millimeters. 0.25 gauge plane
appendix a a - 1 appendix a cpu introduction a.1 introduction the ez-usb?s cpu is an enhanced 8051. this appendix introduces the processor, its interface to the ez-usb logic, and describes architectural differences from a standard 8051. figure a-1 is a block diagram of the ez-usb?s 8051-based cpu. figure a-1. ez-usb cpu features crystal oscillator 8-bit cpu register ram (256 bytes) serial port1 serial port0 timer2 timer1 timer0 bus control interrupt control i/o ports* * the ez-usb family implements i/o ports differently than in the standard 8051
ez-usb technical reference manual a - 2 ez-usb technical reference manual v1.10 a.2 8051 enhancements the ez-usb uses the standard 8051 instruction set, so it?s supported by industry-standard 8051 compilers and assemblers. instructions execute faster on the ez-usb than on the standard 8051: ? wasted bus cycles are eliminated; an instruction cycle uses only four clocks, rather than the standard 8051?s 12 clocks. ? the ez-usb?s cpu clock runs at 24mhz ? twice the clock speed of the standard 8051. in addition to speed improvements, the ez-usb includes the following architectural enhance- ments to the cpu: ? a second data pointer ? a second usart ? a third, 16-bit timer (timer2) ? a high-speed external memory interface with a non-multiplexed 16-bit address bus ? eight additional interrupts (int2-int6, wakeup, t2, and usart1) ? variable movx timing to accommodate fast and slow ram peripherals ? two autopointers (auto-incrementing data pointers) ? vectored usb interrupts ? sleep mode with two wakeup sources ? an i2c bus controller that runs at 100 or 400 khz ? ez-usb-specific sfrs ? separate buffers for the setup and data portions of a usb control transfer ? a hardware pointer for setup data, plus logic to process entire control transfers automatically ? breakpoint facility a.3 performance overview the ez-usb has been designed to offer increased performance by executing instructions in a 4-clock bus cycle, as opposed to the 12-clock bus cycle in the standard 8051 (see figure a-2).
appendix a a - 3 this shortened bus timing improves the instruction execution rate for most instructions by a factor of three over the standard 8051 architectures. some instructions require a different number of instruction cycles on the ez-usb than they do on the standard 8051. in the standard 8051, all instructions except for mul and div take one or two instruction cycles to complete. in the ez-usb, instructions can take between one and five instruc- tion cycles to complete. however, due to the shortened bus timing of the ez-usb, every instruction executes faster than on a standard 8051, and the average speed improvement over the entire instruction set is approximately 2.5. table a-1 catalogs the speed improvements. figure a-2. ez-usb to standard 8051 timing comparison table a-1 ez-usb speed compared to standard 8051 of the 246 ez-usb opcodes... 150 execute at 3.0 standard speed 51 execute at 1.5 standard speed 43 execute at 2.0 standard speed 2 execute at 2.4 standard speed average improvement: 2.5 note : comparison is between ez-usb and standard 8051 running at the same clock frequency. psen ale xtal1 ad0-ad7 psen port2 ez-usb standard port2 single-byte, single-cycle instruction timing ad0-ad7 4 12 8051
ez-usb technical reference manual a - 4 ez-usb technical reference manual v1.10 a.4 software compatibility the ez-usb is object-code-compatible with the industry-standard 8051 microcontroller. that is, object code compiled with an industry-standard 8051 compiler or assembler executes on the ez- usb and is functionally equivalent. however, because the ez-usb uses a different instruction tim- ing than the standard 8051, existing code with timing loops may require modification. the ez-usb instruction timing is identical to that of the dallas semiconductor ds80c320. a.5 803x/805x feature comparison table a-2 provides a feature-by-feature comparison between the ez-usb and several common 803x/805x devices. a.6 ez-usb/ds80c320 differences although the ez-usb is similar to the ds80c320 in terms of hardware features and instruction cycle timing, there are some important differences between the ez-usb and the ds80c320. table a-2 comparison between ez-usb and other 803x/805x devices feature intel dallas ds80c320 cypress ez-usb 8031 8051 80c32 80c52 clocks per instruction cycle 12 12 12 12 4 4 program / data memory - 4 kb rom - 8 kb rom - 8 kb ram internal ram 128 bytes 128 bytes 256 bytes 256 bytes 256 bytes 256 bytes data pointers 1 1 1 1 2 2 serial ports 1 1 1 1 2 2 16-bit timers 2 2 3 3 3 3 interrupt sources (internal and external) 5 5 6 6 13 13 stretch data-memory cycles no no no no yes yes
appendix a a - 5 a.6.1 serial ports the ez-usb does not implement serial port framing-error detection and does not implement slave address comparison for multiprocessor communications. therefore, the ez-usb also does not implement the following sfrs: saddr0, saddr1, saden0, and saden1. a.6.2 timer 2 the ez-usb does not implement timer 2 downcounting mode or the downcount enable bit (tmod2, bit 0). also, the ez-usb does not implement timer 2 output enable (t2oe) bit (tmod2, bit 1). therefore, the tmod2 sfr is also not implemented in the ez-usb. the ez-usb timer 2 overflow output is active for one clock cycle. in the ds80c320, the timer 2 overflow output is a square wave with a 50% duty cycle. a.6.3 timed access protection the ez-usb does not implement timed access protection and, therefore, does not implement the ta sfr. a.6.4 watchdog timer the ez-usb does not implement a watchdog timer. a.6.5 power fail detection the ez-usb does not implement a power fail detection circuit. a.6.6 port i/o the ez-usb?s port i/o implementation is significantly different from that of the ds80c320, mainly because of the alternate functions shared with most of the i/o pins. see chapter 4 ez-usb input/ output .
ez-usb technical reference manual a - 6 ez-usb technical reference manual v1.10 a.6.7 interrupts although the basic interrupt structure of the ez-usb is similar to that of the ds80c320, five of the interrupt sources are different: for more information, refer to appendix c . a.7 ez-usb register interface the ez-usb peripheral logic (usb, i/o ports, i2c controller, etc.) is controlled via a set of memory mapped registers and buffers at addresses 0x7b40 through 0x7fff. these registers and their functions are described throughout this manual. a full description of every ez-usb register appears in chapter 12, "ez-usb registers." a.8 ez-usb internal ram figure a-3. ez-usb internal data ram like the standard 8051, the ez-usb contains 128 bytes of internal data ram at addresses 0x00-0x7f and a partially populated sfr space at addresses 0x80-0xff. an additional 128 indi- rectly-addressed bytes of internal data ram (sometimes called ?idata?) are also available at addresses 0x80-0xff. table a-3 differences between ez-usb and ds80c320 interrupts interrupt priority dallas ds80c320 cypress ez-usb 0 power fail resume (usb wakeup) 8 external interrupt 2 usb 9 external interrupt 3 i2c bus 12 watchdog timer external interrupt 6 lower 128 direct addr sfr space direct addr upper 128 indirect addr 0x00 0x7f 0x80 0xff
appendix a a - 7 all other on-chip ez-usb ram (program/data memory, endpoint buffer memory, and the ez-usb control registers) is addressed as though it were off-chip 8051 memory. ez-usb firmware reads or writes these bytes as data using the movx (?move external?) instruction, even though the ez-usb ram and register set is actually inside the ez-usb chip. off-chip memory attached to the ez-usb address and data buses (80-pin package only) can also be accessed by the movx instruction. ez- usb logic encodes its memory strobe and select signals (rd , wr , cs , oe , and psen ) to elimi- nate the need for external logic to separate the on-chip and off-chip memory spaces; see chapter 3, "ez-usb memory." . a.9 i/o ports the ez-usb implements i/o ports differently than a standard 8051 , as described in chapter 4 ez-usb input/output . the ez-usb has up to three 8-bit wide, bidirectional i/o ports. each port is associated with three registers: ? an ?oex? register, which sets the input/output direction of each of the 8 port pins (0 = input, 1 = output). ? an ?outx? register. values written to outx appear on the pins configured as outputs. ? a ?pinsx? register. values read from pinsx indicate the states of the 8 pins, regardless of input/output configuration. most i/o pins have alternate functions which are selected using configuration registers. when an alternate configuration is selected for an i/o pin, the corresponding oex bit is ignored (see section 4.2 ). the default (power-on reset) state of all i/o ports is: alternate configurations off , all i/o pins configured as inputs . a.10 interrupts all standard 8051 interrupts, plus additional interrupts, are supported by the ez-usb. table a-4 lists the ez-usb interrupts.
ez-usb technical reference manual a - 8 ez-usb technical reference manual v1.10 the ez-usb uses int2 for 21 different usb interrupts. to help determine which interrupt is active, the ez-usb provides a feature called autovectoring, which dynamically changes the address pointed to by the ?jump? instruction at the int2 vector address. this second level of vectoring automatically transfers control to the appropriate usb interrupt service routine (isr). the ez-usb interrupt system, including a full description of the autovector mechanism, is the subject of chap- ter 9, "ez-usb interrupts." a.11 power control the ez-usb implements a low-power mode that allows it to be used in usb bus-powered devices (which are required by the usb specification to draw no more than 500 a when suspended) and other low-power applications. the mechanism by which the ez-usb enters and exits this low- power mode is described in detail in chapter 11 ez-usb power management . a.12 special function registers (sfr) the ez-usb was designed to keep coding as standard as possible, to allow easy integration of existing 8051 software development tools. the ez-usb sfr registers are summarized in table a- 5. standard 8051 sfrs are shown in normal type and ez-usb-added sfrs are shown in bold type. full details of the sfrs can be found in chapter 12, "ez-usb registers." table a-4 ez-usb interrupts standard 8051 interrupts additional ez-usb interrupts source int0 pin pc2 / int0 int1 pin pc3 / int1 timer 0 internal, timer 0 timer 1 internal, timer 1 tx0 & rx0 internal, usart0 int2 internal, usb int3 internal, i2c bus controller int4 pin pb4/int4 int5 pin pb5/int5 int6 pin pb6/int6 wakeup pin wakeup or usb core tx1 & rx1 internal, usart1 timer 2 internal, timer 2
appendix a a - 9 table a-5 ez-usb special function registers (sfr) all unlabed sfrs are reserved. in table a-6, sfr bit positions that contain a 0 or a 1 cannot be written to and, when read, always return the value shown (0 or 1). sfr bit positions that contain ?-? are available but not used. table a-7 lists the reset values for the sfrs. detailed descriptions of the sfrs appear with the associated hardware descriptions in appendix c and in chapter 12, "ez-usb registers." x 8x 9x ax bx cx dx ex fx 0 scon1 psw acc b 1sp exif sbuf1 2dpl0 mpage 3dph0 4 dpl1 5 dph1 6 dps 7pcon 8 tcon scon0 ie ip t2con eicon eie eip 9 tmod sbuf0 atl0 rcap2l btl1 rcap2h cth0 tl2 dth1 th2 e ckcon f spc_fnc
ez-usb technical reference manual a - 10 ez-usb technical reference manual v1.10 table a-6 special function registers register bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 addr sp 81h dpl0 82h dph0 83h dpl1 (1) 84h dph1 (1) 85h dps (1) 0000000sel86h pcon smod0 - 1 1 gf1 gf0 stop idle 87h tcon tf1 tr1 tf0 tr0 ie1 it1 ie0 it0 88h tmod gate c/t m1 m0 gate c/t m1 m0 89h tl0 8ah tl1 8bh th0 8ch th1 8dh ckcon (1) - - t2m t1m t0m md2 md1 md0 8eh spc_fnc (1) 0000000wrs8fh exif (1) ie5 ie4 i2cint usbint 1 0 0 0 91h mpage (1) 92h scon0 sm0_0 sm1_0 sm2_0 ren_0 tb8_0 rb8_0 ti_0 ri_0 98h sbuf0 99h ie ea es1 et2 es0 et1 ex1 et0 ex0 a8h ip 1 ps1 pt2 ps0 pt1 px1 pt0 px0 b8h scon1 (1) sm0_1 sm1_1 sm2_1 ren_1 tb8_1 rb8_1 ti_1 ri_1 c0h sbuf1 (1) c1h t2con tf2 exf2 rclk tclk exen2 tr2 c/t2 cp/rl2 c8h rcap2l cah rcap2h cbh tl2 cch th2 cdh psw cy ac f0 rs1 rs0 ov f1 p d0h eicon (1) smod11eresiresiint6000d8h acc e0h eie (1) 111ewdiex5ex4ei2ceusbe8h b f0h eip (1) 1 1 1 px6 px5 px4 pi2c pusb f8h (1) not part of standard 8051 architecture.
appendix a a - 11 table a-7 special function register reset values register bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 addr sp 0000011181h dpl0 0000000082h dph0 0000000083h dpl1 (1) 0000000084h dph1 (1) 0000000085h dps (1) 0000000086h pcon 0011000087h tcon 0000000088h tmod 0000000089h tl0 000000008ah tl1 000000008bh th0 000000008ch th1 000000008dh ckcon (1) 000000018eh spc_fnc (1) 000000008fh exif (1) 0000100091h mpage (1) 0000000092h scon00000000098h sbuf00000000099h ie 00000000a8h ip 10000000b8h scon1 (1) 00000000c0h sbuf1 (1) 00000000c1h t2con00000000c8h rcap2l00000000cah rcap2h00000000cbh tl2 00000000cch th2 00000000cdh psw 00000000d0h eicon (1) 01000000d8h acc 00000000e0h eie (1) 11100000e8h b 00000000f0h eip (1) 11100000f8h (1) not part of standard 8051 architecture.
ez-usb technical reference manual a - 12 ez-usb technical reference manual v1.10 a.13 external address/data buses the 80-pin version of the ez-usb provides external, non-multiplexed 16-bit address and 8-bit data buses. this differs from the standard 8051, which multiplexes eight pins among three sources: i/o port 0, the external data bus, and the low byte of the external address bus. a standard 8051 system with external memory requires a demultiplexing address latch, strobed by the 8051 ale (address latch enable) pin. the external latch is not required by the ez-usb chip, and no ale signal is provided. in addition to eliminating the need for this external latch, the non- multiplexed ez-usb bus saves one cycle per memory-fetch and allows external memory to be connected without sacrificing i/o pins. the ez-usb is the sole master of the bus, providing read and write signals to the off-chip memory. the address bus is output-only, and cannot be floated. a.14 reset the various ez-usb resets and their effects are described in chapter 10, "ez-usb resets." .
appendix b b - 13 appendix b cpu architectural overview b.1 internal data ram as shown in figure b-1, the ez-usb?s internal data ram is divided into three distinct regions: the ?lower 128?, the ?upper 128?, and ?sfr space?. the lower 128 and upper 128 are general-pur- pose ram; the sfr space contains ez-usb control and status registers. figure b-1. internal data ram organization b.1.1 the lower 128 the lower 128 occupies internal data ram locations 0x00-0x7f. all of the lower 128 may be accessed as general-purpose ram, using either direct or indirect addressing (for more information on the ez-usb addressing modes, see section b.2, "instruction set"). 0x00 0xff 0x7f 0x80 lower 128 upper 128 sfr space 0xff 0x80 lower 128 0x00 r0-r7 (bank 0) 0x07 0x08 r0-r7 (bank 1) 0x0f 0x10 r0-r7 (bank 2) r0-r7 (bank 3) 0x17 0x18 0x1f 0x20 0x2f 0x30 0x7f 0 0 7 78 . . . . . . . . bit-addressable ram general- purpose direct or indirect addressing indirect addressing only direct addressing only 0 0 10 11 register bank select (psw.4:3)
ez-usb technical reference manual b - 14 ez-usb technical reference manual v1.10 two segments of the lower 128 may additionally be accessed in other ways. ? locations 0x00-0x1f comprise four banks of 8 registers each, numbered r0 through r7. the current bank is selected via the ?register-select? bits (rs1:rs0) in the psw special- function register; code which references registers r0-r7 will access them only in the cur- rently-selected bank. ? locations 0x20-0x2f are bit-addressable. each of the 128 bits in this segment may be individually addressed, either by its bit address (0x00 to 0x7f) or by reference to the byte which contains it (0x20.0 to 0x2f.7). b.1.2 the upper 128 the upper 128 occupies internal data ram locations 0x80-0xff; all 128 bytes may be accessed as general-purpose ram, but only by using indirect addressing (for more information on the ez- usb addressing modes, see section b.2, "instruction set"). since the ez-usb?s stack is internally accessed using indirect addressing, it?s a good idea to put the stack in the upper 128; this frees the more-efficiently-accessed lower 128 for general-pur- pose use. b.1.3 sfr (special function register) space the sfr space, like the upper 128, is accessed at internal data ram locations 0x80-0xff. the ez-usb keeps sfr space separate from the upper 128 by using different addressing modes to access the two regions: sfrs may only be accessed using direct addressing, and the upper 128 may only be accessed using indirect addressing. the sfr space contains ez-usb control and status registers; an overview is in section b.2.4, "special function registers", and a full description of all the sfrs is in chapter 12 "ez-usb reg- isters" . the sixteen sfrs at locations 0x80, 0x88, ...., 0xf0, 0xf8 are bit-addressable. each of the 128 bits in these registers may be individually addressed, either by its bit address (0x80 to 0xff) or by reference to the byte which contains it (e.g., 0x80.0, 0xc8.7, etc.). b.2 instruction set all ez-usb instructions are binary-code-compatible with the standard 8051. the ez-usb instruc- tions affect bits, flags, and other status functions just as the 8051 instructions do. instruction tim- ing, however, is different both in terms of the number of clock cycles per instruction cycle and the number of instruction cycles used by each instruction. table b-2 lists the ez-usb instruction set and the number of instruction cycles required to com- plete each instruction. table b-1 defines the symbols and mnemonics used in table b-2.
appendix b b - 15 table b-1 legend for instruction set table symbol function a accumulator rn register (r0?r7, in the bank selected by rs1:rs0) direct internal ram location (0x00 - 0x7f in the ?lower 128?, or 0x80 - 0xff in ?sfr? space) @ri internal ram location (0x00 - 0x7f in the ?lower 128?, or 0x80 - 0xff in the ?upper 128?) pointed to by r0 or r1 rel program-memory offset (-128 to +127 bytes relative to the first byte of the following instruction). used by conditional jumps and sjmp. bit bit address (0x20 - x2f in the ?lower 128,? and sfrs 0x80, 0x88, ...., 0xf0, 0xf8) #data 8-bit constant (0 - 255) #data16 16-bit constant (0 - 65535) addr16 16-bit destination address; used by lcall and ljmp, which branch anywhere in program memory addr11 11-bit destination address; used by acall and ajmp, which branch only within the cur- rent 2k page of program memory (i.e., the upper 5 address bits are copied from the pc) pc program counter; holds the address of the currently-executing instruction. for the pur- poses of ?acall?, ?ajmp?, and ?movc a,@a+pc? instructions, the pc holds the address of the first byte of the instruction following the currently-executing instruction. table b-2 ez-usb instruction set mnemonic description bytes cycles psw flags affected opcode (hex) arithmetic add a, rn add register to a 1 1 cy ov ac 28-2f add a, direct add direct byte to a 2 2 cy ov ac 25 add a, @ri add data memory to a 1 1 cy ov ac 26-27 add a, #data add immediate to a 2 2 cy ov ac 24 addc a, rn add register to a with carry 1 1 cy ov ac 38-3f addc a, direct add direct byte to a with carry 2 2 cy ov ac 35 addc a, @ri add data memory to a with carry 1 1 cy ov ac 36-37 addc a, #data add immediate to a with carry 2 2 cy ov ac 34 subb a, rn subtract register from a with borrow 1 1 cy ov ac 98-9f subb a, direct subtract direct byte from a with borrow 2 2 cy ov ac 95 subb a, @ri subtract data memory from a with borrow 1 1 cy ov ac 96-97 subb a, #data subtract immediate from a with borrow 2 2 cy ov ac 94 inc a increment a 1 1 04 inc rn increment register 1 1 08-0f inc direct increment direct byte 2 2 05
ez-usb technical reference manual b - 16 ez-usb technical reference manual v1.10 inc @ ri increment data memory 1 1 06-07 dec a decrement a 1 1 14 dec rn decrement register 1 1 18-1f dec direct decrement direct byte 2 2 15 dec @ri decrement data memory 1 1 16-17 inc dptr increment data pointer 1 3 a3 mul ab multiply a and b (unsigned; product in b:a) 1 5 cy=0 ov a4 div ab divide a by b (unsigned; quotient in a, remainder in b) 15cy=0 ov84 da a decimal adjust a 1 1 cy d4 logical anl, rn and register to a 1 1 58-5f anl a, direct and direct byte to a 2 2 55 anl a, @ri and data memory to a 1 1 56-57 anl a, #data and immediate to a 2 2 54 anl direct, a and a to direct byte 2 2 52 anl direct, #data and immediate data to direct byte 3 3 53 orl a, rn or register to a 1 1 48-4f orl a, direct or direct byte to a 2 2 45 orl a, @ri or data memory to a 1 1 46-47 orl a, #data or immediate to a 2 2 44 orl direct, a or a to direct byte 2 2 42 orl direct, #data or immediate data to direct byte 3 3 43 xrl a, rn exclusive-or register to a 1 1 68-6f xrl a, direct exclusive-or direct byte to a 2 2 65 xrl a, @ri exclusive-or data memory to a 1 1 66-67 xrl a, #data exclusive-or immediate to a 2 2 64 xrl direct, a exclusive-or a to direct byte 2 2 62 xrl direct, #data exclusive-or immediate to direct byte 3 3 63 clr a clear a 1 1 e4 cpl a complement a 1 1 f4 swap a swap nibbles of a 1 1 c4 rl a rotate a left 1 1 23 rlc a rotate a left through carry 1 1 cy 33 rr a rotate a right 1 1 03 rrc a rotate a right through carry 1 1 cy 13 data transfer mov a, rn move register to a 1 1 e8-ef table b-2 ez-usb instruction set (continued) mnemonic description bytes cycles psw flags affected opcode (hex)
appendix b b - 17 mov a, direct move direct byte to a 2 2 e5 mov a, @ri move data byte at ri to a 1 1 e6-e7 mov a, #data move immediate to a 2 2 74 mov rn, a move a to register 1 1 f8-ff mov rn, direct move direct byte to register 2 2 a8-af mov rn, #data move immediate to register 2 2 78-7f mov direct, a move a to direct byte 2 2 f5 mov direct, rn move register to direct byte 2 2 88-8f mov direct, direct move direct byte to direct byte 3 3 85 mov direct, @ri move data byte at ri to direct byte 2 2 86-87 mov direct, #data move immediate to direct byte 3 3 75 mov @ri, a mov a to data memory at address ri 1 1 f6-f7 mov @ri, direct move direct byte to data memory at address ri 22 a6-a7 mov @ri, #data move immediate to data memory at address ri 22 76-77 mov dptr, #data16 move 16-bit immediate to data pointer 3 3 90 movc a, @a+dptr move code byte at address dptr+a to a 1 3 93 movc a, @a+pc move code byte at address pc+a to a 1 3 83 movx a, @ri move external data at address ri to a 1 2-9* e2-e3 movx a, @dptr move external data at address dptr to a 1 2-9* e0 movx @ri, a move a to external data at address ri 1 2-9* f2-f3 movx @dptr, a move a to external data at address dptr 1 2-9* f0 push direct push direct byte onto stack 2 2 c0 pop direct pop direct byte from stack 2 2 d0 xch a, rn exchange a and register 1 1 c8-cf xch a, direct exchange a and direct byte 2 2 c5 xch a, @ri exchange a and data memory at address ri 11 c6-c7 xchd a, @ri exchange the low-order nibbles of a and data memory at address ri 11 d6-d7 * number of cycles is user-selectable. see section b.2.2. "stretch memory cycles (wait states)" . boolean clr c clear carry 1 1 cy=0 c3 clr bit clear direct bit 2 2 c2 setb c set carry 1 1 cy=1 d3 setb bit set direct bit 2 2 d2 cpl c complement carry 1 1 cy b3 table b-2 ez-usb instruction set (continued) mnemonic description bytes cycles psw flags affected opcode (hex)
ez-usb technical reference manual b - 18 ez-usb technical reference manual v1.10 cpl bit complement direct bit 2 2 b2 anl c, bit and direct bit to carry 2 2 cy 82 anl c, /bit and inverse of direct bit to carry 2 2 cy b0 orl c, bit or direct bit to carry 2 2 cy 72 orl c, /bit or inverse of direct bit to carry 2 2 cy a0 mov c, bit move direct bit to carry 2 2 cy a2 mov bit, c move carry to direct bit 2 2 92 branching acall addr11 absolute call to subroutine 2 3 11-f1 lcall addr16 long call to subroutine 3 4 12 ret return from subroutine 1 4 22 reti return from interrupt 1 4 32 ajmp addr11 absolute jump unconditional 2 3 01-e1 ljmp addr16 long jump unconditional 3 4 02 sjmp rel short jump (relative address) 2 3 80 jc rel jump if carry = 1 2 3 40 jnc rel jump if carry = 0 2 3 50 jb bit, rel jump if direct bit = 1 3 4 20 jnb bit, rel jump if direct bit = 0 3 4 30 jbc bit, rel jump if direct bit = 1, then clear the bit 3 4 10 jmp @ a+dptr jump indirect to address dptr+a 1 3 73 jz rel jump if accumulator = 0 2 3 60 jnz rel jump if accumulator is non-zero 2 3 70 cjne a, direct, rel compare a to direct byte; jump if not equal 3 4 cy b5 cjne a, #d, rel compare a to immediate; jump if not equal 3 4 cy b4 cjne rn, #d, rel compare register to immediate; jump if not equal 34cy b8-bf cjne @ ri, #d, rel compare data memory to immediate; jump if not equal 34cy b6-b7 djnz rn, rel decrement register; jump if not zero 2 3 d8-df djnz direct, rel decrement direct byte; jump if not zero 3 4 d5 miscellaneous nop no operation 1 1 00 there is an additional reserved opcode (a5) that performs the same function as nop. all mnemonics are copyright 1980, intel corporation. table b-2 ez-usb instruction set (continued) mnemonic description bytes cycles psw flags affected opcode (hex)
appendix b b - 19 b.2.1 instruction timing instruction cycles in the ez-usb are 4 clock cycles in length, as opposed to the 12 clock cycles per instruction cycle in the standard 8051. for full details of the instruction-cycle timing differences between the ez-usb and the standard 8051, see section a.3, "performance overview" . in the standard 8051, all instructions except for mul and div take one or two instruction cycles to complete. in the ez-usb, instructions can take between one and five instruction cycles to com- plete. for calculating the timing of software loops, etc., use the ?cycles? column from table b-2. the ?bytes? column indicates the number of bytes occupied by each instruction. by default, the ez-usb?s timer/counters run at 12 clock cycles per increment so that timer-based events have the same timing as with the standard 8051. the timers can also be configured to run at 4 clock cycles per increment to take advantage of the higher speed of the ez-usb?s cpu. b.2.2 stretch memory cycles (wait states) the ez-usb can execute a movx instruction in as few as 2 instruction cycles. however, it is sometimes desirable to stretch this value (for example to access slow memory or slow memory- mapped peripherals such as usarts or lcds). the ez-usb?s ?stretch memory cycle? feature enables ez-usb firmware to adjust the speed of data memory accesses (program-memory code fetches are not affected). the three lsbs of the clock control register (ckcon, at sfr location 0x8e) control the stretch value; stretch values between zero and seven may be used. a stretch value of zero adds zero instruction cycles, resulting in movx instructions which execute in two instruction cycles. a stretch value of seven adds seven instruction cycles, resulting in movx instructions which execute in nine instruction cycles. the stretch value can be changed dynamically under program control. at power-on-reset, the stretch value defaults to one (three-cycle movx); for the fastest data mem- ory access, ez-usb software must explicitly set the stretch value to zero. the stretch value affects only data memory access ( not program memory). the stretch value affects the width of the read/write strobe and all related timing. using a higher stretch value results in a wider read/write strobe, which allows the memory or peripheral more time to respond. table b-3 lists the data memory access speeds for stretch values zero through seven. md2-0 are the three lsbs of the clock control register (ckcon.2-0). the strobe width timing shown is typi- cal.
ez-usb technical reference manual b - 20 ez-usb technical reference manual v1.10 b.2.3 dual data pointers the ez-usb employs dual data pointers to accelerate data memory block moves. the standard 8051 data pointer (dptr) is a 16-bit pointer used to address external data ram or peripherals. the ez-usb maintains the standard data pointer as dptr0 at the standard sfr locations 0x82 (dpl0) and 0x83 (dph0); it is not necessary to modify existing code to use dptr0. the ez-usb adds a second data pointer (dptr1) at sfr locations 0x84 (dpl1) and 0x85 (dph1). the sel bit (bit 0 of the dptr select register, dps, at sfr 0x86), selects the active pointer. when sel = 0, instructions that use the dptr will use dpl0:dph0. when sel = 1, instructions that use the dptr will use dpl1:dph1. no other bits of the dps sfr are used. all dptr-related instructions use the data pointer selected by the sel bit. switching between the two data pointers by toggling the sel bit relieves ez-usb firmware from the burden of saving source and destination addresses when doing a block move; therefore, using dual data pointers provides significantly increased efficiency when moving large blocks of data. the fastest way to toggle the sel bit between the two data pointers is via the ?inc dps? instruc- tion, which toggles bit 0 of dps between 0 and 1. the sfr locations related to the dual data pointers are: 0x82dpl0 dptr0 low byte 0x83dph0 dptr0 high byte 0x84dpl1 dptr1 low byte 0x85dph1 dptr1 high byte 0x86dps dptr select (bit 0) table b-3 data memory stretch values md2 md1 md0 movx instruction cycles read/write strobe width (clocks) read/write strobe width (nanoseconds) 000 2 2 83.3 ns 0 0 1 3 (default) 4 167 ns 010 4 8 333 ns 011 5 12 500 ns 100 6 16 667 ns 101 7 20 833 ns 1 1 0 8 24 1000 ns 1 1 1 9 28 1167 ns
appendix b b - 21 b.2.4 special function registers the four sfrs listed below are related to cpu operation and program execution. except for the stack pointer sp, each of the registers is bit addressable. 0x81 sp stack pointer 0xd0 psw program status word 0xe0 acc accumulator register 0xf0 b b register table b-4 lists the functions of the psw bits. table b-4 psw register - sfr 0xd0 bit function psw.7 cy - carry flag. this is the unsigned carry bit. the cy flag is set when an arithmetic operation results in a carry from bit 7 to bit 8, and cleared otherwise. in other words, it acts as a virtual bit 8. the cy flag is cleared on multiplication and division. see the ?psw flags affected? column in table b-2. psw.6 ac - auxiliary carry flag. set to 1 when the last arithmetic operation resulted in a carry into (dur- ing addition) or borrow from (during subtraction) the high order nibble, otherwise cleared to 0 by all arithmetic operations. see the ?psw flags affected? column in table b-2. psw.5 f0 - user flag 0. available to ez-usb firmware for general purpose. psw.4 rs1 - register bank select bit 1. psw.3 rs0 - register bank select bit 0. rs1:rs0 select a register bank in internal ram: rs1 rs0 bank selected 0 0 register bank 0, addresses 0x00-0x07 0 1 register bank 1, addresses 0x08-0x0f 1 0 register bank 2, addresses 0x10-0x17 1 1 register bank 3, addresses 0x18-0x1f psw.2 ov - overflow flag. this is the signed carry bit. the ov flag is set when a positive sum exceeds 0x7f or a negative sum (in two?s complement notation) exceeds 0x80. after a multiply, ov = 1 if the result of the multiply is greater than 0xff. after a divide, ov = 1 if a divide-by-0 occurred. see the ?psw flags affected? column in table b-2. psw.1 f1 - user flag 1. available to ez-usb firmware for general purpose. psw.0 p - parity flag. contains the modulo-2 sum of the 8 bits in the accumulator (i.e., set to 1 when the accumulator contains an odd number of ?1? bits, set to 0 when the accumulator contains an even number of ?1? bits).
ez-usb technical reference manual b - 22 ez-usb technical reference manual v1.10
appendix c c - 23 appendix c ez-usb peripherals c.1 introduction this chapter provides technical data about the ez-usb peripheral operation and timing. the topics are: ? timers/counters ? serial interface ? interrupts c.2 timers/counters the ez-usb includes three timer/counters (timer 0, timer 1, and timer 2). each timer/counter can operate either as a timer with a clock rate based on the ez-usb?s internal clock (clk24) or as an event counter clocked by the t0 pin (timer 0), t1 pin (timer 1), or the t2 pin (timer 2). timers 1 and 2 may be used for baud clock generation for the serial interface (see section c.3 for details of the serial interface). each timer/counter consists of a 16-bit register that is accessible to software as two sfrs: ? timer 0 ? th0 and tl0 ? timer 1 ? th1 and tl1 ? timer 2 ? th2 and tl2 c.2.1 803x/805x compatibility the implementation of the timers/counters is similar to that of the dallas semiconductor ds80c320. table c-1 summarizes the differences in timer/counter implementation between the intel 8051, the dallas semiconductor ds80c320, and the ez-usb.
ez-usb technical reference manual c - 24 ez-usb technical reference manual v1.10 c.2.2 timers 0 and 1 timers 0 and 1 operate in four modes, as controlled through the tmod sfr (table c-2) and the tcon sfr (table c-3). the four modes are: ? 13-bit timer/counter (mode 0) ? 16-bit timer/counter (mode 1) ? 8-bit counter with auto-reload (mode 2) ? two 8-bit counters (mode 3, timer 0 only) c.2.2.1 mode 0, 13-bit timer/counter ? timer 0 and timer 1 mode 0 operation is illustrated in figure c-1. in mode 0, the timer is configured as a 13-bit counter that uses bits 0-4 of tl0 (or tl1) and all 8 bits of th0 (or th1). the timer enable bit (tr0/tr1) in the tcon sfr starts the timer. the c/t bit selects the timer/counter clock source: either clk24 or the t0/t1 pins . the timer counts transitions from the selected source as long as the gate bit is 0, or the gate bit is 1 and the corresponding interrupt pin (int0 or int1 ) is 1. when the 13-bit count increments from 0x1fff (all ones), the counter rolls over to all zeros, the tf0 (or tf1) bit is set in the tcon sfr, and the t0out (or t1out) pin goes high for one clock cycle. the upper 3 bits of tl0 (or tl1) are indeterminate in mode 0 and should be ignored. table c-1 timer/counter implementation comparison feature intel 8051 dallas ds80c320 ez-usb number of timers 2 3 3 timer 0/1 overflow available as output signals no no yes; t0out, t1out (one clk24 pulse) timer 2 output enable n/a yes no timer 2 down-count enable n/a yes no timer 2 overflow available as output signal n/a yes yes; t2out (one clk24 pulse)
appendix c c - 25 figure c-1. timer 0/1 - modes 0 and 1 c.2.2.2 mode 1, 16-bit timer/counter ? timer 0 and timer 1 in mode 1, the timer is configured as a 16-bit counter. as illustrated in figure c-1, all 8 bits of the lsb register (tl0 or tl1) are used. the counter rolls over to all zeros when the count increments from 0xffff. otherwise, mode 1 operation is the same as mode 0. tl0 (or tl1) 0 7 4 divide by 12 divide by 4 clk24 t0 (or t1) pin tr0 (or tr1) gate int0 (or int1 ) pin 7 0 tf0 (or tf1) int th0 (or th1) t0m (or t1m) mode 0 mode 1 0 1 0 1 to serial port (timer 1 only) clk c/ t
ez-usb technical reference manual c - 26 ez-usb technical reference manual v1.10 table c-2 tmod register ? sfr 0x89 bit function tmod.7 gate1 - timer 1 gate control. when gate1 = 1, timer 1 will clock only when int1 = 1 and tr1 (tcon.6) = 1. when gate1 = 0, timer 1 will clock only when tr1 = 1, regardless of the state of int1 . tmod.6 c/t 1 - counter/timer select. when c/t 1 = 0, timer 1 is clocked by clk24/4 or clk24/12, depending on the state of t1m (ckcon.4). when c/t 1 = 1, timer 1 is clocked by high-to- low transitions on the t1 pin. tmod.5 m1 - timer 1 mode select bit 1. tmod.4 m0 - timer 1 mode select bit 0. m1 m0 mode 0 0 mode 0 : 13-bit counter 0 1 mode 1 : 16-bit counter 1 0 mode 2 : 8-bit counter with auto-reload 1 1 mode 3 : timer 1 stopped tmod.3 gate0 - timer 0 gate control, when gate0 = 1, timer 0 will clock only when int0 = 1 and tr0 (tcon.4) = 1. when gate0 = 0, timer 0 will clock only when tr0 = 1, regardless of the state of int0 . tmod.2 c/t 0 - counter/timer select. when c/t 0 = 0, timer 0 is clocked by clk24/4 or clk24/12, depending on the state of t0m (ckcon.3). when c/t 0 = 1, timer 0 is clocked by high-to- low transitions on the t0 pin. tmod.1 m1 - timer 0 mode select bit 1. tmod.0 m0 - timer 0 mode select bit 0. m1 m0 mode 0 0 mode 0 : 13-bit counter 0 1 mode 1 : 16-bit counter 1 0 mode 2 : 8-bit counter with auto-reload 1 1 mode 3 : two 8-bit counters
appendix c c - 27 c.2.2.3 mode 2, 8-bit counter with auto-reload ? timer 0 and timer 1 in mode 2, the timer is configured as an 8-bit counter, with automatic reload of the start value on overflow. tl0 (or tl1) is the counter, and th0 (or th1) stores the reload value. as illustrated in figure c-2, mode 2 counter control is the same as for mode 0 and mode 1. when tl0/1 increments from 0xff, the value stored in th0/1 is reloaded into tl0/1. table c-3 tcon register ? srf 0x88 bit function tcon.7 tf1 - timer 1 overflow flag. set to 1 when the timer 1 count overflows; automatically cleared when the ez-usb vectors to the interrupt service routine. tcon.6 tr1 - timer 1 run control. 1 = enable counting on timer 1. tcon.5 tf0 - timer 0 overflow flag. set to 1 when the timer 0 count overflows; automatically cleared when the ez-usb vectors to the interrupt service routine. tcon.4 tr0 - timer 0 run control. 1 = enable counting on timer 0. tcon.3 ie1 - interrupt 1 edge detect. if external interrupt 1 is configured to be edge-sensitive (it1 = 1), ie1 is set when a negative edge is detected on the int1 pin and is automat- ically cleared when the ez-usb vectors to the corresponding interrupt service rou- tine. in this case, ie1 can also be cleared by software. if external interrupt 1 is configured to be level-sensitive (it1 = 0), ie1 is set when the int1 pin is 0 and auto- matically cleared when the int1 pin is 1. in level-sensitive mode, software cannot write to ie1. tcon.2 it1 - interrupt 1 type select. int1 is detected on falling edge when it1 = 1; int1 is detected as a low level when it1 = 0. tcon.1 ie0 - interrupt 0 edge detect. if external interrupt 0 is configured to be edge-sensitive (it0 = 1), ie0 is set when a negative edge is detected on the int0 pin and is automat- ically cleared when the ez-usb vectors to the corresponding interrupt service rou- tine. in this case, ie0 can also be cleared by software. if external interrupt 0 is configured to be level-sensitive (it0 = 0), ie0 is set when the int0 pin is 0 and auto- matically cleared when the int0 pin is 1. in level-sensitive mode, software cannot write to ie0. tcon.0 it0 - interrupt 0 type select. int0 is detected on falling edge when it0 = 1; int0 is detected as a low level when it0 = 0.
ez-usb technical reference manual c - 28 ez-usb technical reference manual v1.10 figure c-2. timer 0/1 - mode 2 c.2.2.4 mode 3, two 8-bit counters ? timer 0 only in mode 3, timer 0 operates as two 8-bit counters. selecting mode 3 for timer 1 simply stops timer 1. as shown in figure c-3, tl0 is configured as an 8-bit counter controlled by the normal timer 0 control bits. tl0 can either count clk24 cycles (divided by 4 or by 12) or high-to-low transitions on the t0 pin, as determined by the c/t bit. the gate function can be used to give counter enable control to the int0 pin. th0 functions as an independent 8-bit counter. however, th0 can only count clk24 cycles (divided by 4 or by 12). the timer 1 control and flag bits (tr1 and tf1) are used as the control and flag bits for th0. when timer 0 is in mode 3, timer 1 has limited usage because timer 0 uses the timer 1 control bit (tr1) and interrupt flag (tf1). timer 1 can still be used for baud rate generation and the timer 1 count values are still available in the tl1 and th1 registers. control of timer 1 when timer 0 is in mode 3 is through the timer 1 mode bits. to turn timer 1 on, set timer 1 to mode 0, 1, or 2. to turn timer 1 off, set it to mode 3. the timer 1 c/t bit and t1m bit are still available to timer 1. therefore, timer 1 can count clk24/4, clk24/12, or high-to-low transitions on the t1 pin. the timer 1 gate function is also available when timer 0 is in mode 3. tl0 (or tl1) 0 7 divide by 12 divide by 4 t0 (or t1) pin tr0 (or tr1) gate int0 (or int1 ) pin 7 0 tf0 (or tf1) th0 (or th1) t0m (or t1m) reload int 0 1 0 1 to serial port (timer 1 only) clk24 clk c/ t
appendix c c - 29 figure c-3. timer 0 - mode 3 c.2.3 timer rate control by default, the ez-usb timers increment every 12 clk24 cycles, just as in the standard 8051. using this default rate allows existing application code with real-time dependencies, such as baud rate, to operate properly. applications that require fast timing can set the timers to increment every 4 clk24 cycles instead, by setting bits in the clock control register (ckcon) at sfr location 0x8e. (see table c-4). each timer?s rate can be set independently. these settings have no effect in counter mode. table c-4 ckcon (sfr 0x8e) timer rate control bits bit function ckcon.5 t2m - timer 2 clock select. when t2m = 0, timer 2 uses clk24/12 (for compatibility with standard 8051); when t2m = 1, timer 2 uses clk24/4. this bit has no effect when timer 2 is configured for baud rate generation. ckcon.4 t1m - timer 1 clock select. when t1m = 0, timer 1 uses clk24/12 (for compatibility with standard 8051); when t1m = 1, timer 1 uses clk24/4. ckcon.3 t0m - timer 0 clock select. when t0m = 0, timer 0 uses clk24/12 (for compatibility with standard 8051); when t0m = 1, timer 0 uses clk24/4. tl0 0 7 divide by 12 divide by 4 t0 pin tr0 gate int0 pin 7 0 tf0 th0 t0m int tr1 tf1 int 0 1 0 1 clk24 clk c/ t
ez-usb technical reference manual c - 30 ez-usb technical reference manual v1.10 c.2.4 timer 2 timer 2 runs only in 16-bit mode and offers several capabilities not available with timers 0 and 1. the modes available for timer 2 are: ? 16-bit timer/counter ? 16-bit timer with capture ? 16-bit timer/counter with auto-reload ? baud rate generator the sfrs associated with timer 2 are: ? t2con (sfr 0xc8) ? timer/counter 2 control register, (see table c-5). ? rcap2l (sfr 0xca) ? used to capture the tl2 value when timer 2 is configured for capture mode, or as the lsb of the 16-bit reload value when timer 2 is configured for auto-reload mode. ? rcap2h (sfr 0xcb) ? used to capture the th2 value when timer 2 is configured for capture mode, or as the msb of the 16-bit reload value when timer 2 is configured for auto-reload mode. ? tl2 (sfr 0xcc) ? lower 8 bits of the 16-bit count. ? th2 (sfr 0xcd) ? upper 8 bits of the 16-bit count.
appendix c c - 31 c.2.4.1 timer 2 mode control table c-6 summarizes how the t2con bits determine the timer 2 mode. table c-5 t2con register ? sfr 0xc8 bit function t2con.7 tf2 - timer 2 overflow flag. hardware will set tf2 when the timer 2 overflows from 0xffff. tf2 must be cleared to 0 by the software. tf2 will only be set to a 1 if rclk and tclk are both cleared to 0. writing a 1 to tf2 forces a timer 2 interrupt if enabled. t2con.6 exf2 - timer 2 external flag. hardware will set exf2 when a reload or capture is caused by a high-to-low transition on the t2ex pin, and exen2 is set. exf2 must be cleared to 0 by software. writing a 1 to exf2 forces a timer 2 interrupt if enabled. t2con.5 rclk - receive clock flag. determines whether timer 1 or timer 2 is used for serial port 0 timing of received data in serial mode 1 or 3. rclk=1 selects timer 2 overflow as the receive clock; rclk=0 selects timer 1 overflow as the receive clock. t2con.4 tclk - transmit clock flag. determines whether timer 1 or timer 2 is used for serial port 0 timing of transmit data in serial mode 1 or 3. tclk=1 selects timer 2 overflow as the trans- mit clock; tclk=0 selects timer 1 overflow as the transmit clock. t2con.3 exen2 - timer 2 external enable. exen2=1 enables capture or reload to occur as a result of a high-to-low transition on the t2ex pin, if timer 2 is not generating baud rates for the serial port. exen2=0 causes timer 2 to ignore all external events on the t2ex pin. t2con.2 tr2 - timer 2 run control flag. tr2=1 starts timer 2; tr2=0 stops timer 2. t2con.1 c/t 2 - counter/timer select. when c/t 2 = 1, timer 2 is clocked by high-to-low transitions on the t2 pin.when c/t 2 = 0 in modes 0, 1, or 2, timer 2 is clocked by clk24/4 or clk24/12, depending on the state of t2m (ckcon.5). when c/t 2 = 0 in mode 3, timer 2 is clocked by clk24/2, regardless of the state of ckcon.5. t2con.0 cp/rl 2 - capture/reload flag. when cp/rl 2=1, timer 2 captures occur on high-to-low tran- sitions of the t2ex pin, if exen2 = 1. when cp/rl 2 = 0, auto-reloads occur when timer 2 overflows or when high-to-low transitions occur on the t2ex pin, if exen2 = 1. if either rclk or tclk is set to 1, cp/rl 2 will not function and timer 2 will operate in auto-reload mode following each overflow. table c-6 timer 2 mode control summary tr2 tclk rclk cp/rl 2 mode 0 x x x timer 2 stopped 1 1 x x baud rate generator 1 x 1 x baud rate generator 1 0 0 0 16-bit timer/counter with auto-reload 1 0 0 1 16-bit timer/counter with capture x = don?t care
ez-usb technical reference manual c - 32 ez-usb technical reference manual v1.10 c.2.5 timer 2 ? 16-bit timer/counter mode figure c-4 illustrates how timer 2 operates in timer/counter mode with the optional capture fea- ture. the c/t 2 bit determines whether the 16-bit counter counts clk24 cycles (divided by 4 or 12), or high-to-low transitions on the t2 pin. the tr2 bit enables the counter. when the count increments from 0xffff, the tf2 flag is set and the t2out pin goes high for one clk24 cycle. c.2.5.1 timer 2 ? 16-bit timer/counter mode with capture the timer 2 capture mode (figure c-4) is the same as the 16-bit timer/counter mode, with the addition of the capture registers and control signals. the cp/rl 2 bit in the t2con sfr enables the capture feature. when cp/rl 2 = 1, a high-to-low transition on the t2ex pin when exen2 = 1 causes the timer 2 value to be loaded into the cap- ture registers rcap2l and rcap2h. figure c-4. timer 2 - timer/counter with capture c.2.6 timer 2 ? 16-bit timer/counter mode with auto-reload when cp/rl 2 = 0, timer 2 is configured for the auto-reload mode illustrated in figure c-5. control of counter input is the same as for the other 16-bit counter modes. when the count increments from 0xffff, timer 2 sets the tf2 flag and the starting value is reloaded into tl2 and th2. soft- ware must preload the starting value into the rcap2l and rcap2h registers. when timer 2 is in auto-reload mode, a reload can be forced by a high-to-low transition on the t2ex pin, if enabled by exen2 = 1. 0 7 divide by 12 divide by 4 clk24 t2 pin tr2 clk 7 0 exf2 t2m int rcap2l tl2 th2 rcap2h 8 15 8 15 exen2 t2ex pin capture tf2 0 1 0 1 c/ t 2 cp/rl 2 = 1
appendix c c - 33 figure c-5. timer 2 - timer/counter with auto reload c.2.7 timer 2 ? baud rate generator mode setting either rclk or tclk to 1 configures timer 2 to generate baud rates for serial port 0 in serial mode 1 or 3. figure c-6 is the functional diagram for the timer 2 baud rate generator mode. in baud rate generator mode, timer 2 functions in auto-reload mode. however, instead of setting the tf2 flag, the counter overflow is used to generate a shift clock for the serial port function. as in normal auto-reload mode, the overflow also causes the pre-loaded start value in the rcap2l and rcap2h registers to be reloaded into the tl2 and th2 registers. when either tclk = 1 or rclk = 1, timer 2 is forced into auto-reload operation, regardless of the state of the cp/rl 2 bit. timer 2 is used as the receive baud clock source when rclk=1, and as the transmit baud clock source when tclk=1. when operating as a baud rate generator, timer 2 does not set the tf2 bit. in this mode, a timer 2 interrupt can only be generated by a high-to-low transition on the t2ex pin setting the exf2 bit, and only if enabled by exen2 = 1. the counter time base in baud rate generator mode is clk24/2. to use an external clock source, set c/t 2 to 1 and apply the desired clock source to the t2 pin. the maximum frequency for an external clock source on the t2 pin is 3 mhz. 0 7 divide by 12 divide by 4 clk24 t2 pin tr2 clk 7 0 exf2 t2m int rcap2l tl2 th2 rcap2h 8 15 8 15 exen2 t2ex pin tf2 0 10 1 c/ t 2 cp/rl 2 = 0
ez-usb technical reference manual c - 34 ez-usb technical reference manual v1.10 figure c-6. timer 2 - baud rate generator mode c.3 serial interface the ez-usb provides two serial ports. serial port 0 operates almost exactly as a standard 8051 serial port; depending on the configured mode (see table c-7), its baud-clock source can be clk24/4 or clk24/12, timer 1, or timer 2. serial port 1 is identical to serial port 0, except that it cannot use timer 2 as its baud rate generator. each serial port can operate in synchronous or asynchronous mode. in synchronous mode, the ez-usb generates the serial clock and the serial port operates in half-duplex mode. in asynchro- nous mode, the serial port operates in full-duplex mode. in all modes, the ez-usb double-buffers the incoming data so that a byte of incoming data can be received while firmware is reading the previously-received byte. each serial port can operate in one of four modes, as outlined in table c-7. divide by 2 t2 pin tr2 0 1 clk clk24 c/ t 2 divide by 16 divide by 16 rx clock tx clock tclk 0 0 1 divide by 2 0 1 1 tl2 th2 exf2 timer 2 interrupt exen2 t2ex pin timer 1 overflow 0 7 7 0 rcap2l rcap2h 8 15 8 15 smod0 rclk
appendix c c - 35 the registers associated with the serial ports are as follows. (registers pcon and eicon also include some functionality which is not part of the serial interface). ? pcon (sfr 0x87) ? bit 7, serial port 0 rate control smod0 (table c-11). ? scon0 (sfr 0x98) ? serial port 0 control (table c-9). ? sbuf0 (sfr 0x99) ? serial port 0 transmit/receive buffer. ? eicon (sfr 0xd8) ? bit 7, serial port 1 rate control smod1 (table c-10). ? scon1 (sfr 0xc0) ? serial port 1 control (table c-12). ? sbuf1 (sfr 0xc1) ? serial port 1 transmit/receive buffer. ? t2con (sfr 0xc8) ? baud clock source for modes 1 and 3 (rclk and tclk in table c- 5). c.3.1 803x/805x compatibility the implementation of the serial interface is similar to that of the dallas semiconductor, ds80c320. table c-8 summarizes the differences in serial interface implementation between the intel 8051, the dallas semiconductor ds80c320, and the ez-usb. table c-7 serial port modes mode sync / async baud-clock source data bits start / stop 9th bit function 0 sync clk24/4 or clk24/12 8 none none 1 async timer 1 (ports 0 and 1), timer 2 (port 0 only), or 8 1 start, 1 stop none 2 async clk24/32 or clk24/64 9 1 start, 1 stop 0, 1, or parity 3 async timer 1 (ports 0 and 1), timer 2 (port 0 only), or 9 1 start, 1 stop 0, 1, or parity table c-8 serial interface implementation comparison feature intel 8051 dallas ds80c320 ez-usb number of serial ports 1 2 2 framing error detection not implemented implemented not implemented slave address comparison for multiprocessor communication not implemented implemented not implemented
ez-usb technical reference manual c - 36 ez-usb technical reference manual v1.10 c.3.2 mode 0 serial mode 0 provides synchronous, half-duplex serial communication. for serial port 0, serial data output occurs on the rxd0out pin, serial data is received on the rxd0 pin, and the txd0 pin provides the shift clock for both transmit and receive. for serial port 1, the corresponding pins are rxd1out, rxd1, and txd1. the serial mode 0 baud rate is either clk24/12 or clk24/4, depending on the state of the sm2_0 bit (or sm2_1 for serial port 1). when sm2_0 = 0, the baud rate is clk24/12, when sm2_0 = 1, the baud rate is clk24/4. mode 0 operation is identical to the standard 8051. data transmission begins when an instruction writes to the sbuf0 (or sbuf1) sfr. the usart shifts the data, lsb first, at the selected baud rate, until the 8-bit value has been shifted out. mode 0 data reception begins when the ren_0 (or ren_1) bit is set and the ri_0 (or ri_1) bit is cleared in the corresponding scon sfr. the shift clock is activated and the usart shifts data, lsb first, in on each rising edge of the shift clock until 8 bits have been received. one clk24 cycle after the 8th bit is shifted in, the ri_0 (or ri_1) bit is set and reception stops until the soft- ware clears the ri bit. figure c-7 through figure c-10 illustrate serial port mode 0 transmit and receive timing for both low-speed (clk24/12) and high-speed (clk24/4) operation. the figures show port 0 signal names, rxd0, rxd0out, and txd0. the timing is the same for port 1 signals rxd1, rxd1out, and txd1, respectively.
appendix c c - 37 table c-9 scon0 register ? sfr 98h bit function scon0.7 sm0_0 - serial port 0 mode bit 0. scon0.6 sm1_0 - serial port 0 mode bit 1, decoded as: sm0_0 sm1_0 mode 000 011 102 113 scon0.5 sm2_0 - multiprocessor communication enable. in modes 2 and 3, this bit enables the mul- tiprocessor communication feature. if sm2_0 = 1 in mode 2 or 3, then ri_0 will not be acti- vated if the received 9th bit is 0. if sm2_0=1 in mode 1, then ri_0 will only be activated if a valid stop is received. in mode 0, sm2_0 establishes the baud rate: when sm2_0=0, the baud rate is clk24/12; when sm2_0=1, the baud rate is clk24/4. scon0.4 ren_0 - receive enable. when ren_0=1, reception is enabled. scon0.3 tb8_0 - defines the state of the 9th data bit transmitted in modes 2 and 3. scon0.2 rb8_0 - in modes 2 and 3, rb8_0 indicates the state of the 9th bit received. in mode 1, rb8_0 indicates the state of the received stop bit. in mode 0, rb8_0 is not used. scon0.1 ti_0 - transmit interrupt flag. indicates that the transmit data word has been shifted out. in mode 0, ti_0 is set at the end of the 8th data bit. in all other modes, ti_0 is set when the stop bit is placed on the txd0 pin. ti_0 must be cleared by firmware. scon0.0 ri_0 - receive interrupt flag. indicates that serial data word has been received. in mode 0, ri_0 is set at the end of the 8th data bit. in mode 1, ri_0 is set after the last sample of the incoming stop bit, subject to the state of sm2_0. in modes 2 and 3, ri_0 is set at the end of the last sample of rb8_0. ri_0 must be cleared by firmware. table c-10 eicon (sfr 0xd8) smod1 bit bit function eicon.7 smod1 - serial port 1 baud rate doubler enable. when smod1 = 1 the baud rate for serial port is doubled. table c-11 pcon (sfr 0x87) smod0 bit bit function pcon.7 smod0 - serial port 0 baud rate double enable. when smod0 = 1, the baud rate for serial port 0 is doubled.
ez-usb technical reference manual c - 38 ez-usb technical reference manual v1.10 table c-12 scon1 register ? sfr c0h bit function scon1.7 sm0_1 - serial port 1 mode bit 0. scon1.6 sm1_1 - serial port 1 mode bit 1, decoded as: sm0_1 sm1_1 mode 000 011 102 113 scon1.5 sm2_1 - multiprocessor communication enable. in modes 2 and 3, this bit enables the multiprocessor communication feature. if sm2_1 = 1 in mode 2 or 3, then ri_1 will not be activated if the received 9th bit is 0. if sm2_1=1 in mode 1, then ri_1 will only be activated if a valid stop is received. in mode 0, sm2_1 establishes the baud rate: when sm2_1=0, the baud rate is clk24/12; when sm2_1=1, the baud rate is clk24/4. scon1.4 ren_1 - receive enable. when ren_1=1, reception is enabled. scon1.3 tb8_1 - defines the state of the 9th data bit transmitted in modes 2 and 3. scon1.2 rb8_1 - in modes 2 and 3, rb8_1 indicates the state of the 9th bit received. in mode 1, rb8_1 indicates the state of the received stop bit. in mode 0, rb8_1 is not used. scon1.1 ti_1 - transmit interrupt flag. indicates that the transmit data word has been shifted out. in mode 0, ti_1 is set at the end of the 8th data bit. in all other modes, ti_1 is set when the stop bit is placed on the txd1 pin. ti_1 must be cleared by the software . scon1.0 ri_1 - receive interrupt flag. indicates that serial data word has been received. in mode 0, ri_1 is set at the end of the 8th data bit. in mode 1, ri_1 is set after the last sample of the incoming stop bit, subject to the state of sm2_1. in modes 2 and 3, ri_1 is set at the end of the last sample of rb8_1. ri_1 must be cleared by the software .
appendix c c - 39 figure c-7. serial port mode 0 receive timing - low speed operation figure c-8. serial port mode 0 receive timing - high speed operation at both low and high speed in mode 0, data on rxd0 is sampled two clk24 cycles before the ris- ing clock edge on txd0. clk24 d0 d1 d2 d3 d4 d5 d6 d7 ri txd0 rxd0 rxd0out ti d0 d1 d2 d3 d4 d5 d6 d7 clk24 ri txd0 rxd0 rxd0out ti
ez-usb technical reference manual c - 40 ez-usb technical reference manual v1.10 figure c-9. serial port mode 0 transmit timing - low speed operation figure c-10. serial port mode 0 transmit timing - high speed operation c.3.3 mode 1 mode 1 provides standard asynchronous, full-duplex communication, using a total of 10 bits: 1 start bit, 8 data bits, and 1 stop bit. for receive operations, the stop bit is stored in rb8_0 (or rb8_1). data bits are received and transmitted lsb first. mode 1 operation is identical to that of the standard 8051 when timer 1 uses clk24/12, (t1m=0, the default). clk24 ri txd0 rxd0 rxd0out ti d0 d1 d2 d3 d4 d5 d6 d7 d0 d1 d2 d3 d4 d5 d6 d7 clk24 ri txd0 rxd0 rxd0out ti
appendix c c - 41 c.3.3.1 mode 1 baud rate the mode 1 baud rate is a function of timer overflow. serial port 0 can use either timer 1 or timer 2 to generate baud rates. serial port 1 can only use timer 1. the two serial ports can run at the same baud rate if they both use timer 1, or different baud rates if serial port 0 uses timer 2 and serial port 1 uses timer 1. each time the timer increments from its maximum count (0xff for timer 1 or 0xffff for timer 2), a clock is sent to the baud rate circuit. that clock is then divided by 16 to generate the baud rate. when using timer 1, the smod0 (or smod1) bit selects whether or not to divide the timer 1 roll- over rate by 2. therefore, when using timer 1, the baud rate is determined by the equation: when using timer 2, the baud rate is determined by the equation: to use timer 1 as the baud rate generator, it is generally best to use timer 1 mode 2 (8-bit counter with auto-reload), although any counter mode can be used. in mode 2, the timer 1 reload value is stored in the th1 register, which makes the complete formula for timer 1: to derive the required th1 value from a known baud rate when t1m=0, use the equation: to derive the required th1 value from a known baud rate when t1m=1, use the equation: timer 1 overflow baud rate = 32 2 smodx timer 2 overflow baud rate = 16 baud rate = 32 2 smodx (12 - 8 t1m) (256 - th1) clk24 th1 = 2 smodx clk24 384 baud rate 256 - x th1 = 2 smodx clk24 128 x baud rate 256 -
ez-usb technical reference manual c - 42 ez-usb technical reference manual v1.10 very low serial port baud rates may be achieved with timer 1 by enabling the timer 1 interrupt, configuring timer 1 to mode 1, and using the timer 1 interrupt to initiate a 16-bit software reload. table c-13 lists sample reload values for a variety of common serial port baud rates, using timer 1 operating in mode 2 (tmod.5:4=10) with a clk24/4 clock source (t1m=1) and the full timer roll- over (smod1=1). more accurate baud rates may be achieved by using timer 2 as the baud rate generator. to use timer 2 as the baud rate generator, configure timer 2 in auto-reload mode and set the tclk and/ or rclk bits in the t2con sfr. tclk selects timer 2 as the baud rate generator for the trans- mitter; rclk selects timer 2 as the baud rate generator for the receiver. the 16-bit reload value for timer 2 is stored in the rcap2l and rca2h sfrs, which makes the equation for the timer 2 baud rate: to derive the required rcap2h and rcap2l values from a known baud rate, use the equation: when either rclk or tclk is set, the tf2 flag is not set on a timer 2 rollover and the t2ex reload trigger is disabled. table c-13 timer 1 reload values for common serial port mode 1 baud rates nominal rate th1 reload value actual rate error 57600 f9 53571 -6.99% 38400 f6 37500 -2.34% 28800 f3 28846 +0.16% 19200 ec 18750 -2.34% 9600 d9 9615 +0.16% 4800 b2 4807 +0.16% 2400 64 2403 +0.16% settings: smod=1, c/t =0, timer1 mode=2, t1m=1 note: using rates that are off by 2% or more will not work in all systems. baud rate = 32 (65536 - 256rcap2h + rcap2l) clk24 rcap2h:l = clk24 32 baud rate 65536 -
appendix c c - 43 table c-14 lists sample rcap2h:l reload values for a variety of common serial baud rates. c.3.3.2 mode 1 transmit figure c-11 illustrates the mode 1 transmit timing. in mode 1, the usart begins transmitting after the first rollover of the divide-by-16 counter after the software writes to the sbuf0 (or sbuf1) reg- ister. the usart transmits data on the txd0 (or txd1) pin in the following order: start bit, 8 data bits (lsb first), stop bit. the ti_0 (or ti_1) bit is set 2 clk24 cycles after the stop bit is transmitted. c.3.4 mode 1 receive figure c-12 illustrates the mode 1 receive timing. reception begins at the falling edge of a start bit received on the rxd0 (or rxd1) pin, when enabled by the ren_0 (or ren_1) bit. for this pur- pose, the rxd0 (or rxd1) pin is sampled 16 times per bit for any baud rate. when a falling edge of a start bit is detected, the divide-by-16 counter used to generate the receive clock is reset to align the counter rollover to the bit boundaries. for noise rejection, the serial port establishes the content of each received bit by a majority deci- sion of 3 consecutive samples in the middle of each bit time. for the start bit, if the falling edge on the rxd0 (or rxd1) pin is not verified by a majority decision of 3 consecutive samples (low), then the serial port stops reception and waits for another falling edge on the rxd0 (or rxd1) pin. at the middle of the stop bit time, the serial port checks for the following conditions: ? ri_0 (or ri_1) = 0 ? if sm2_0 (or sm2_1) = 1, the state of the stop bit is 1 (if sm2_0 (or sm2_1) = 0, the state of the stop bit doesn?t matter. table c-14 timer 2 reload values for common serial port mode 1 baud rates nominal rate rcap2h:l reload value actual rate error 57600 fff3 57692 +0.16% 38400 ffec 37500 -2.34% 28800 ffe6 28846 +0.16% 19200 ffd9 19230 +0.16% 9600 ffb2 9615 +0.16% 4800 ff64 4807 +0.16% 2400 fec8 2403 +0.16% note: using rates that are off by 2.3% or more will not work in all systems.
ez-usb technical reference manual c - 44 ez-usb technical reference manual v1.10 if the above conditions are met, the serial port then writes the received byte to the sbuf0 (or sbuf1) register, loads the stop bit into rb8_0 (or rb8_1), and sets the ri_0 (or ri_1) bit. if the above conditions are not met, the received data is lost, the sbuf register and rb8 bit are not loaded, and the ri bit is not set. after the middle of the stop bit time, the serial port waits for another high-to-low transition on the (rxd0 or rxd1) pin. figure c-11. serial port 0 mode 1 transmit timing figure c-12. serial port 0 mode 1 receive timing write to sbuf0 ri_0 txd0 rxd0 rxd0out shift tx clk ti_0 d0 d1 d2 d3 d4 d5 d6 d7 stop start ri_0 txd0 rxd0 rxd0out shift rx clk ti_0 d0 d1 d2 d3 d4 d5 d6 d7 stop start bit detector sampling
appendix c c - 45 c.3.5 mode 2 mode 2 provides asynchronous, full-duplex communication, using a total of 11 bits: 1 start bit, 8 data bits, a programmable 9th bit, and 1 stop bit. the data bits are transmitted and received lsb first. for transmission, the 9th bit is determined by the value in tb8_0 (or tb8_1). to use the 9th bit as a parity bit, move the value of the p bit (sfr psw.0) to tb8_0 (or tb8_1). the mode 2 baud rate is either clk24/32 or clk24/64, as determined by the smod0 (or smod1) bit. the formula for the mode 2 baud rate is: mode 2 operation is identical to the standard 8051. c.3.5.1 mode 2 transmit figure c-13 illustrates the mode 2 transmit timing. transmission begins after the first rollover of the divide-by-16 counter following a software write to sbuf0 (or sbuf1). the usart shifts data out on the txd0 (or txd1) pin in the following order: start bit, data bits (lsb first), 9th bit, stop bit. the ti_0 (or ti_1) bit is set when the stop bit is placed on the txd0 (or txd1) pin. c.3.5.2 mode 2 receive figure c-14 illustrates the mode 2 receive timing. reception begins at the falling edge of a start bit received on the rxd0 (or rxd1) pin, when enabled by the ren_0 (or ren_1) bit. for this pur- pose, the rxd0 (or rxd1) pin is sampled 16 times per bit for any baud rate. when a falling edge of a start bit is detected, the divide-by-16 counter used to generate the receive clock is reset to align the counter rollover to the bit boundaries. for noise rejection, the serial port establishes the content of each received bit by a majority deci- sion of 3 consecutive samples in the middle of each bit time. for the start bit, if the falling edge on the rxd0 (or rxd1) pin is not verified by a majority decision of 3 consecutive samples (low), then the serial port stops reception and waits for another falling edge on the rxd0 (or rxd1) pin. at the middle of the stop bit time, the serial port checks for the following conditions: ? ri_0 (or ri_1) = 0 ? if sm2_0 (or sm2_1) = 1, the state of the stop bit is 1. (if sm2_0 (or sm2_1) = 0, the state of the stop bit doesn?t matter.) if the above conditions are met, the serial port then writes the received byte to the sbuf0 (or sbuf1) register, loads the stop bit into rb8_0 (or rb8_1), and sets the ri_0 (or ri_1) bit. if the above conditions are not met, the received data is lost, the sbuf register and rb8 bit are not baud rate = 2 smodx clk24 64
ez-usb technical reference manual c - 46 ez-usb technical reference manual v1.10 loaded, and the ri bit is not set. after the middle of the stop bit time, the serial port waits for another high-to-low transition on the rxd0 ( or rxd1) pin. figure c-13. serial port 0 mode 2 transmit timing figure c-14. serial port 0 mode 2 receive timing c.3.6 mode 3 mode 3 provides asynchronous, full-duplex communication, using a total of 11 bits: 1 start bit, 8 data bits, a programmable 9th bit, and 1 stop bit. the data bits are transmitted and received lsb first. ri_0 txd0 rxd0 rxd0out shift tx clk ti_0 d0 d1 d2 d3 d4 d5 d6 d7 stop start write to sbuf0 tb8 ri_0 txd0 rxd0 rxd0out shift rx clk ti_0 d0 d1 d2 d3 d4 d5 d6 d7 stop start rb8 bit detector sampling
appendix c c - 47 the mode 3 transmit and operations are identical to mode 2. the mode 3 baud rate generation is identical to mode 1. that is, mode 3 is a combination of mode 2 protocol and mode 1 baud rate. figure c-15 illustrates the mode 3 transmit timing. figure c-16 illustrates the mode 3 receive tim- ing. mode 3 operation is identical to that of the standard 8051 when timer 1 uses clk24/12, (t1m=0, the default). figure c-15. serial port 0 mode 3 transmit timing figure c-16. serial port 0 mode 3 receive timing ri_0 txd0 rxd0 rxd0out shift tx clk ti_0 d0 d1 d2 d3 d4 d5 d6 d7 stop start write to sbuf0 tb8 ri_0 txd0 rxd0 rxd0out shift rx clk ti_0 d0 d1 d2 d3 d4 d5 d6 d7 stop start rb8 bit detector sampling
ez-usb technical reference manual c - 48 ez-usb technical reference manual v1.10 c.4 interrupts the ez-usb?s interrupt architecture is an enhanced and expanded version of the standard 8051?s. the ez-usb responds to the interrupts shown in table c-15; interrupt sources that are not present in the standard 8051 are shown in bold type. . the natural priority column in table c-15 shows the ez-usb interrupt priorities. the ez-usb can assign each interrupt to a high or low priority group; priorities within the groups are resolved using the natural priorities. c.5 interrupt-control sfrs the following sfrs are associated with interrupt control: ? ie - sfr 0xa8 (table c-16) ? ip - sfr 0xb8 (table c-17) ? exif - sfr 0x91 (table c-18) table c-15 ez-usb interrupts ez-usb interrupt source interrupt vector natural priority ie0 int0 pin 0x0003 1 tf0 timer 0 overflow 0x000b 2 ie1 int1 pin 0x0013 3 tf1 timer 1 overflow 0x001b 4 ri_0 & ti_0 usart0 rx & tx 0x0023 5 tf2 timer 2 overflow 0x002b 6 resume wakeup or usb resume 0x0033 0 (highest priority) ri_1 & ti_1 usart1 rx & tx 0x003b 7 usbint usb 0x0043 8 i2cint i2c bus 0x004b 9 ie4 int4 pin 0x0053 10 ie5 int5 pin 0x005b 11 ie6 int6 pin 0x0063 12
appendix c c - 49 ? eicon - sfr 0xd8 (table c-19) ? eie - sfr 0xe8 (table c-20) ? eip - sfr 0xf8 (table c-21) the ie and ip sfrs provide interrupt enable and priority control for the standard interrupt unit, as with the standard 8051. additionally, these sfrs provide control bits for the serial port 1 interrupt. the exif, eicon, eie and eip registers provide flags, enable control, and priority control. table c-16 ie register ? sfr 0xa8 bit function ie.7 ea - global interrupt enable. controls masking of all interrupts except usb wakeup (resume). ea = 0 disables all interrupts except usb wakeup. when ea = 1, interrupts are enabled or masked by their individual enable bits. ie.6 es1 - enable serial port 1 interrupt. es1 = 0 disables serial port 1 interrupts (ti_1 and ri_1). es1 = 1 enables interrupts generated by the ti_1 or ri_1 flag. ie.5 et2 - enable timer 2 interrupt. et2 = 0 disables timer 2 interrupt (tf2). et2=1 enables interrupts generated by the tf2 or exf2 flag. ie.4 es0 - enable serial port 0 interrupt. es0 = 0 disables serial port 0 interrupts (ti_0 and ri_0). es0=1 enables interrupts generated by the ti_0 or ri_0 flag. ie.3 et1 - enable timer 1 interrupt. et1 = 0 disables timer 1 interrupt (tf1). et1=1 enables interrupts generated by the tf1 flag. ie.2 ex1 - enable external interrupt 1. ex1 = 0 disables external interrupt 1 (int1). ex1=1 enables interrupts generated by the int1 pin. ie.1 et0 - enable timer 0 interrupt. et0 = 0 disables timer 0 interrupt (tf0). et0=1 enables interrupts generated by the tf0 flag. ie.0 ex0 - enable external interrupt 0. ex0 = 0 disables external interrupt 0 (int0). ex0=1 enables interrupts generated by the int0 pin.
ez-usb technical reference manual c - 50 ez-usb technical reference manual v1.10 table c-17 ip register ? sfr 0xb8 bit function ip.7 reserved . read as 1. ip.6 ps1 - serial port 1 interrupt priority control. ps1 = 0 sets serial port 1 interrupt (ti_1 or ri_1) to low priority. ps1 = 1 sets serial port 1 interrupt to high priority. ip.5 pt2 - timer 2 interrupt priority control. pt2 = 0 sets timer 2 interrupt (tf2) to low priority. pt2 = 1 sets timer 2 interrupt to high priority. ip.4 ps0 - serial port 0 interrupt priority control. ps0 = 0 sets serial port 0 interrupt (ti_0 or ri_0) to low priority. ps0 = 1 sets serial port 0 interrupt to high priority. ip.3 pt1 - timer 1 interrupt priority control. pt1 = 0 sets timer 1 interrupt (tf1) to low priority. pt1 = 1 sets timer 1 interrupt to high priority. ip.2 px1 - external interrupt 1 priority control. px1 = 0 sets external interrupt 1 (int1) to low priority. pt1 = 1 sets external interrupt 1 to high priority. ip.1 pt0 - timer 0 interrupt priority control. pt0 = 0 sets timer 0 interrupt (tf0) to low priority. pt0 = 1 sets timer 0 interrupt to high priority. ip.0 px0 - external interrupt 0 priority control. px0 = 0 sets external interrupt 0 (int0) to low priority. px0 = 1 sets external interrupt 0 to high priority. table c-18 exif register ? sfr 0x91 bit function exif.7 ie5 - external interrupt 5 flag. ie5 = 1 indicates a falling edge was detected at the int5 pin. ie5 must be cleared by software. setting ie5 in software generates an interrupt, if enabled. exif.6 ie4 - external interrupt 4 flag. the ?int4? interrupt indicates that a rising edge was detected at the int4 pin. ie4 must be cleared by software. setting ie4 in software generates an interrupt, if enabled. exif.5 i2cint - i2c bus interrupt flag. i2cint = 1 indicates an i2c bus interrupt. i2cint must be cleared by software. setting i2cint in software generates an interrupt, if enabled. exif.4 usbint - usb interrupt flag. usbint = 1 indicates an usb interrupt. usbint must be cleared by software. setting usbint in software generates an interrupt, if enabled. exif.3 reserved . read as 1. exif.2-0 reserved . read as 0.
appendix c c - 51 table c-19 eicon register ? sfr 0xd8 bit function eicon.7 smod1 - serial port 1 baud rate doubler enable. when smod1 = 1, the baud rate for serial port 1 is doubled. eicon.6 reserved . read as 1. eicon.5 eresi - enable resume interrupt. eresi = 0 disables the resume inter- rupt. eresi = 1 enables interrupts generated by the resume event. eicon.4 resi - wakeup interrupt flag. resi = 1 indicates a false-to-true transition was detected at the wakeup pin, or that usb activity has resumed from the suspended state. resi must be cleared by software before exiting the interrupt service routine, otherwise the interrupt will immediately be reas- serted. setting resi = 1 in software generates a wakeup interrupt, if enabled. eicon.3 int6 - external interrupt 6. when int6 = 1, the int6 pin has detected a low to high transition. int6 must be cleared by software. setting this bit in soft- ware generates an int6 interrupt, if enabled. eicon.2-0 reserved . read as 0. table c-20 eie register ? sfr 0xe8 bit function eie.7-5 reserved. read as 1. eie.4 ex6 - enable external interrupt 6. ex6 = 0 disables external interrupt 6 (int6). ex6 = 1 enables interrupts generated by the int6 pin. eie.3 ex5 - enable external interrupt 5. ex5 = 0 disables external interrupt 5 (int5). ex5 = 1 enables interrupts generated by the int5 pin. eie.2 ex4 - enable external interrupt 4. ex4 = 0 disables external interrupt 4 (int4). ex4 = 1 enables interrupts generated by the int4 pin. eie.1 ei2c - enable i2c bus interrupt (i2cint). ei2c = 0 disables the i2 c bus interrupt. ei2c = 1 enables interrupts generated by the i 2c bus controller. eie.0 eusb - enable usb interrupt (usbint). eusb = 0 disables usb interrupts. eusb = 1 enables interrupts generated by the usb interface.
ez-usb technical reference manual c - 52 ez-usb technical reference manual v1.10 c.5.1 803x/805x compatibility the implementation of interrupts is similar to that of the dallas semiconductor ds80c320. table c-22 summarizes the differences in interrupt implementation between the intel 8051, the dallas semiconductor ds80c320, and the ez-usb. table c-21 eip register ? sfr 0xf8 bit function eip.7-5 reserved . read as 1. eip.4 px6 - external interrupt 6 priority control. px6 = 0 sets external interrupt 6 (int6) to low priority. px6 = 1 sets external interrupt 6 to high priority. eip.3 px5 - external interrupt 5 priority control. px5 = 0 sets external interrupt 5 (int5 ) to low priority. px5=1 sets external interrupt 5 to high priority. eip.2 px4 - external interrupt 4 priority control. px4 = 0 sets external interrupt 4 (int4) to low priority. px4=1 sets external interrupt 4 to high priority. eip.1 pi2c - i2cint priority control. pi2c = 0 sets i2 c bus interrupt to low priority. pi2c=1 sets i2 c bus interrupt to high priority. eip.0 pusb - usbint priority control. pusb = 0 sets usb interrupt to low priority. pusb=1 sets usb interrupt to high priority. table c-22 summary of interrupt compatibility feature intel 8051 dallas ds80c320 cypress ez-usb power fail interrupt not implemented internally generated replaced with resume interrupt external interrupt 0 implemented implemented implemented timer 0 interrupt implemented implemented implemented external interrupt 1 implemented implemented implemented timer 1 interrupt implemented implemented implemented serial port 0 interrupt implemented implemented implemented timer 2 interrupt not implemented implemented implemented serial port 1 interrupt not implemented implemented implemented external interrupt 2 not implemented implemented replaced with autovectored usb interrupt external interrupt 3 not implemented implemented replaced with i2c bus interrupt external interrupt 4 not implemented implemented implemented external interrupt 5 not implemented implemented implemented watchdog timer interrupt not implemented internally generated replaced with external interrupt 6 real-time clock interrupt not implemented implemented not implemented
appendix c c - 53 c.6 interrupt processing when an enabled interrupt occurs, the ez-usb completes the instruction it?s currently executing, then vectors to the address of the interrupt service routine (isr) associated with that interrupt (see table c-23). the ez-usb executes the isr to completion unless another interrupt of higher prior- ity occurs. each isr ends with a reti (return from interrupt) instruction. after executing the reti , the ez-usb continues executing firmware at the instruction following the one which was executing when the interrupt occurred. the ez-usb always completes the instruction in progress before servicing an interrupt. if the instruction in progress is reti , or a write access to any of the ip, ie, eip, or eie sfrs, the ez- usb completes one additional instruction before servicing the interrupt. c.6.1 interrupt masking the ea bit in the ie sfr (ie.7) is a global enable for all interrupts except the resume (usb wakeup) interrupt, which is always enabled. when ea = 1, each interrupt is enabled or masked by its individual enable bit. when ea = 0, all interrupts are masked except the usb wakeup interrupt. table c-23 provides a summary of interrupt sources, flags, enables, and priorities.
ez-usb technical reference manual c - 54 ez-usb technical reference manual v1.10 c.6.1.1 interrupt priorities there are two stages of interrupt priority: assigned interrupt level and natural priority. assigned pri- ority is set by ez-usb firmware; natural priority is as shown in table c-23, and is fixed. the assigned interrupt level (highest, high, or low) takes precedence over natural priority. the resume (usb wakeup) interrupt always has highest assigned priority and is the only interrupt that can have highest assigned priority. all other interrupts can be assigned either high or low pri- ority. in addition to an assigned priority level (high or low), each interrupt also has a natural priority, as listed in table c-23. simultaneous interrupts with the same assigned priority level (for example, both high) are resolved according to their natural priority. for example, if int0 and int1 are both assigned high priority and both occur simultaneously, int0 takes precedence due to its higher nat- ural priority. once an interrupt is being serviced, only an interrupt of higher assigned priority level can interrupt the service routine. that is, an isr for a low-assigned-level interrupt can only be interrupted by a high-assigned-level interrupt. an isr for a high-assigned-level interrupt can only be interrupted by the resume interrupt. table c-23 interrupt flags, enables, priority control, and vectors interrupt description interrupt request flag interrupt enable assigned priority control natural priority interrupt vector resume resume interrupt eicon.4 eicon.5 always highest 0 (highest) 0x0033 int0 external interrupt 0 tcon.1 ie.0 ip.0 1 0x0003 tf0 timer 0 interrupt tcon.5 ie.1 ip.1 2 0x000b int1 external interrupt 1 tcon.3 ie.2 ip.2 3 0x0013 tf1 timer 1 interrupt tcon.7 ie.3 ip.3 4 0x001b ti_0 or ri_0 serial port 0 transmit or receive interrupt scon0.1 (ti.0) scon0.0 (ri_0) ie.4 ip.4 5 0x0023 tf2 or exf2 timer 2 interrupt t2con.7 (tf2) t2con.6 (exf2) ie.5 ip.5 6 0x002b ti_1 or ri_1 serial port 1 transmit or receive interrupt scon1.1 (ti_1) scon1.0 (ri_1) ie.6 ip.6 7 0x003b usbint autovectored usb interrupt exif.4 eie.0 eip.0 8 0x0043 i2c in t i2 c bus interrupt exif.5 eie.1 eip.1 9 0x004b int4 external interrupt 4 exif.6 eie.2 eip.2 10 0x0053 int5 external interrupt 5 exif.7 eie.3 eip.3 11 0x005b int6 external interrupt 6 eicon.3 eie.4 eip.4 12 0x0063
appendix c c - 55 c.6.2 interrupt sampling the internal timers and serial ports generate interrupts by setting the interrupt flag bits shown in table c-23. these interrupts are sampled once per instruction cycle (i.e., once every 4 clk24 cycles). int0 and int1 are both active low and can be programmed to be either edge-sensitive or level- sensitive, through the it0 and it1 bits in the tcon sfr. when itx = 0, intx is level-sensitive and the ez-usb sets the iex flag when the intx pin is sampled low. when itx = 1, intx is edge-sensi- tive and the ez-usb sets the iex flag when the intx pin is sampled high then low on consecutive samples. the remaining five interrupts (int 4-6, usb & i 2 c bus interrupts) are edge-sensitive only. int6 and int4 are active high and int5 is active low. to ensure that edge-sensitive interrupts are detected, the interrupt pins should be held in each state for a minimum of one instruction cycle (4 clk24 cycles). level-sensitive interrupts are not latched; their pins must remain asserted until the interrupt is serviced. c.6.3 interrupt latency interrupt response time depends on the current state of the ez-usb. the fastest response time is 5 instruction cycles: 1 to detect the interrupt, and 4 to perform the lcall to the isr. the maximum latency is 13 instruction cycles. this 13-cycle latency occurs when the ez-usb is currently executing a reti instruction followed by a mul or div instruction. the 13 instruction cycles in this case are: 1 to detect the interrupt, 3 to complete the reti , 5 to execute the div or mul , and 4 to execute the lcall to the isr. this13-instruction-cycle latency excludes autovector latency for the usb interrupts (see section 9.10). autovectoring adds a fixed 4 instruction cycles, so the maximum latency for an autovectored usb interrupt is 13 + 4 = 17 instruction cycles.
ez-usb technical reference manual c - 56 ez-usb technical reference manual v1.10
appendix d d - 57 appendix d a n 2 1 x x reg i ster s u m m a r y the following table is a summary of all the ez-usb registers. in the ?b7-b0? columns, bit positions that contain a 0 or a 1 cannot be written to and, when read, always return the value shown (0 or 1). bit positions that contain ?-? are available but unused. the ?default? column shows each register?s power-on-reset value (?x? indicates ?undefined?). the ?access? column indicates each register?s read/write accessibility.
ez-usb technical reference manual d - 58 ez-usb technical reference manual v1.10
ez-usb technical reference manual v1.10 appendix d - 59 ez-usb registers & buffers register summary addr name description d7 d6 d5 d4 d3 d2 d1 d0 default cpu access notes endpoint 0-7 data buffers cpu access codes 7b40 out7buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw rw = read or write, 7b80 in7buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw r, r = read-only, 7bc0 out6buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw w, w = write-only 7c00 in6buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw b = both (read & write) 7c40 out5buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw 7c80 in5buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw 7cc0 out4buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw 7d00 in4buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw 7d40 out3buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw 7d80 in3buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw 7dc0 out2buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw 7e00 in2buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw 7e40 out1buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw 7e80 in1buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw 7ec0 out0buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw 7f00 in0buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw 7f40-7f5f(reserved) isochronous data 7f60 out8data endpoint 8 out data d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx r 7f61 out9data endpoint 9 out data d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx r 7f62 out10data endpoint 10 out data d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx r 7f63 out11data endpoint 11 out data d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx r 7f64 out12data endpoint 12 out data d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx r 7f65 out13data endpoint 13 out data d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx r 7f66 out14data endpoint 14 out data d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx r 7f67 out15data endpoint 15 out data d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx r 7f68 in8data endpoint 8 in data d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx w 7f69 in9data endpoint 9 in data d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx w 7f6a in10data endpoint 10 in data d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx w 7f6b in11data endpoint 11 in data d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx w 7f6c in12data endpoint 12 in data d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx w 7f6d in13data endpoint 13 in data d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx w 7f6e in14data endpoint 14 in data d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx w 7f6f in15data endpoint 15 in data d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx w isochronous byte counts 7f70 out8bch ep8 out byte count h 0 0 0 0 0 0 d9 d8 xxxxxxxx r 7f71 out8bcl ep8 out byte count l d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx r 7f72 out9bch ep9 out byte count h 0 0 0 0 0 0 d9 d8 xxxxxxxx r 7f73 out9bcl ep9 out byte count l d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx r
ez-usb technical reference manual v1.10 appendix d - 60 ez-usb registers & buffers 7f74 out10bch ep10 out byte count h 0 0 0 0 0 0 d9 d8 xxxxxxxx r 7f75 out10bcl ep10 out byte count l d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx r 7f76 out11bch ep11 out byte count h 0 0 0 0 0 0 d9 d8 xxxxxxxx r 7f77 out11bcl ep11 out byte count l d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx r 7f78 out12bch ep12 out byte count h 0 0 0 0 0 0 d9 d8 xxxxxxxx r 7f79 out12bcl ep12 out byte count l d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx r 7f7a out13bch ep13 out byte count h 0 0 0 0 0 0 d9 d8 xxxxxxxx r 7f7b out13bcl ep13 out byte count l d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx r 7f7c out14bch ep14 out byte count h 0 0 0 0 0 0 d9 d8 xxxxxxxx r 7f7d out14bcl ep14 out byte count l d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx r 7f7e out15bch ep15 out byte count h 0 0 0 0 0 0 d9 d8 xxxxxxxx r 7f7f out15bcl ep15 out byte count l d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx r 7f80-7f91 (reserved) cpu registers 7f92 cpucs control & status rv3 rv2 rv1 rv0 0 0 clk24oe 8051res ( )0011 rrrrrrbr rv[3..0] = chip rev 7f93 portacfg port a configuration rxd1out rxd0out frd fwr cs oe t1out t0out 00000000 rw 0=port, 1=alt function 7f94 portbcfg port b configuration t2out int6 int5 int4 txd1 rxd1 t2ex t2 00000000 rw 0=port, 1=alt function 7f95 portccfg port c configuration rd wr t1 t0 int1 int0 txd0 rxd0 00000000 rw 0=port, 1=alt function input-output port registers 7f96 outa output register a outa7 outa6 outa5 outa4 outa3 outa2 outa1 outa0 00000000 rw 7f97 outb output register b outb7 outb6 outb5 outb4 outb3 outb2 outb1 outb0 00000000 rw 7f98 outc output register c outc7 outc6 outc5 outc4 outc3 outc2 outc1 outc0 00000000 rw 7f99 pinsa port pins a pina7 pina6 pina5 pina4 pina3 pina2 pina1 pina0 xxxxxxxx r 7f9a pinsb port pins b pinb7 pinb6 pinb5 pinb4 pinb3 pinb2 pinb1 pinb0 xxxxxxxx r 7f9b pinsc port pins c pinc7 pinc6 pinc5 pinc4 pinc3 pinc2 pinc1 pinc0 xxxxxxxx r 7f9c oea output enable a oea7 oea6 oea5 oea4 oea3 oea2 oea1 oea0 00000000 rw 0=off, 1=drive 7f9d oeb output enable b oeb7 oeb6 oeb5 oeb4 oeb3 oeb2 oeb1 oeb0 00000000 rw 0=off, 1=drive 7f9e oec output enable c oec7 oec6 oec5 oec4 oec3 oec2 oec1 oec0 00000000 rw 0=off, 1=drive 7f9f (reserved) isochronous control/status registers 7fa0 isoerr iso out endpoint error iso15err iso14err iso13err iso12err iso11err iso10err iso9err iso8err xxxxxxxx r 7fa1 isoctl isochronous control * * * * ppstat mbz mbz isodisab 0000x000 rrrrrbbb "mbz" = must be zero 7fa2 zbcout zero byte count bits ep15 ep14 ep13 ep12 ep11 ep10 ep9 ep8 xxxxxxxx r 7fa3 (reserved) 7fa4 (reserved) i 2 c registers 7fa5 i2cs control & status start stop lastrd id1 id0 berr ack done 000xx000 bbbrrrrr 7fa6 i2dat data d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw 7fa7 (reserved) interrupts 7fa8 ivec interrupt vector 0 iv4 iv3 iv2 iv1 iv0 0 0 00000000 r 7fa9 in07irq epin interrupt request in7ir in6ir in5ir in4ir in3ir in2ir in1ir in0ir 00000000 rw 1=request addr name description d7 d6 d5 d4 d3 d2 d1 d0 default cpu access notes
ez-usb technical reference manual v1.10 appendix d - 61 ez-usb registers & buffers 7faa out07irq epout interrupt request out7ir out6ir out5ir out4ir out3ir out2ir out1ir out0ir xxxxxxxx rw 1=request 7fab usbirq usb interrupt request * * * uresir suspir sutokir sofir sudavir 00000000 rw 1=request 7fac in07ien ep0-7in int enables in7ien in6ien in5ien in4ien in3ien in2ien in1ien in0ien 00000000 rw 1=enabled 7fad out07ien ep0-7out int enables out7ien out6ien out5ien out4ien out3ien out2ien out1ien out0ien 00000000 rw 1=enabled 7fae usbien usb int enables * * * uresie suspie sutokie sofie sudavie 00000000 rw 1=enabled 7faf usbbav breakpoint & autovector **** break bppulse bpen aven xxxxxx00 rw 1=enabled 7fb0 (reserved) 7fb1 (reserved) 7fb2 bpaddrh breakpoint address h a15 a14 a13 a12 a11 a10 a9 a8 00000000 rw 7fb3 bpaddrl breakpoint address l a7 a6 a5 a4 a3 a2 a1 a0 00000000 rw bulk endpoints 0-7 7fb4 ep0cs control & status * * * * outbsy inbsy hsnak ep0stall 00001000 rrrrrrbb for ep0in and ep0out 7fb5 in0bc byte count * d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw * this bits are random 7fb6 in1cs control & status * * * * * * in1bsy in1stl 00000000 rrrrrrrb at power-on. once 7fb7 in1bc byte count * d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw operational, these bits 7fb8 in2cs control & status * * * * * * in2bsy in2stl 00000000 rrrrrrrb read as zeros. 7fb9 in2bc byte count * d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw 7fba in3cs control & status * * * * * * in3bsy in3stl 00000000 rrrrrrrb 7fbb in3bc byte count * d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw 7fbc in4cs control & status * * * * * * in4bsy in4stl 00000000 rrrrrrrb 7fbd in4bc byte count * d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw 7fbe in5cs control & status * * * * * * in5bsy in5stl 00000000 rrrrrrrb 7fbf in5bc byte count * d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw 7fc0 in6cs control & status * * * * * * in6bsy in6stl 00000000 rrrrrrrb 7fc1 in6bc byte count * d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw 7fc2 in7cs control & status * * * * * * in7bsy in7stl 00000000 rrrrrrrb 7fc3 in7bc byte count * d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw 7fc4 (reserved) 7fc5 out0bc byte count * d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw 7fc6 out1cs control & status * * * * * * out1bsy out1stl 00000010 rrrrrrrb 7fc7 out1bc byte count * d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw 7fc8 out2cs control & status * * * * * * out2bsy out2stl 00000010 rrrrrrrb 7fc9 out2bc byte count * d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw 7fca out3cs control & status * * * * * * out3bsy out3stl 00000010 rrrrrrrb 7fcb out3bc byte count * d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw 7fcc out4cs control & status * * * * * * out4bsy out4stl 00000010 rrrrrrrb 7fcd ou4tbc byte count * d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw 7fce out5cs control & status * * * * * * out5bsy out5stl 00000010 rrrrrrrb 7fcf out5bc byte count * d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw 7fd0 out6cs control & status * * * * * * out6bsy out6stl 00000010 rrrrrrrb 7fd1 out6bc byte count * d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw 7fd2 out7cs control & status * * * * * * out7bsy out7stl 00000010 rrrrrrrb addr name description d7 d6 d5 d4 d3 d2 d1 d0 default cpu access notes
ez-usb technical reference manual v1.10 appendix d - 62 ez-usb registers & buffers 7fd3 out7bc byte count * d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw global usb registers 7fd4 sudptrh setup data ptr h a15 a14 a13 a12 a11 a10 a9 a8 xxxxxxxx rw 7fd5 sudptrl setup data ptr l a7 a6 a5 a4 a3 a2 a1 a0 xxxxxxxx rw 7fd6 usbcs usb control & status wakesrc * * * discon discoe renum sigrsume 00000100 brrrbbbb clear b7 by writing "1" 7fd7 togctl toggle control q s r io 0 ep2 ep1 ep0 xxxxxxxx rbbbbbbb 7fd8 usbframel frame number l fc7 fc6 fc5 fc4 fc3 fc2 fc1 fc0 xxxxxxxx r 7fd9 usbframeh frame number h 0 0 0 0 0 fc10 fc9 fc8 xxxxxxxx r 7fda (reserved) 7fdb fnaddr function address 0 fa6 fa5 fa4 fa3 fa2 fa1 fa0 xxxxxxxx r 7fdc (reserved) 7fdd usbpair endpoint control isosend0 * pr6out pr4out pr2out pr6in pr4in pr2in 0x000000 rw prx = 1 to pair ep 7fde in07val input endpoint 0-7 valid in7val in6val in5val in4val in3val in2val in1val 1 01010111 rw val =1 means valid 7fdf out07val output endpoint 0-7 valid out7val out6val out5val out4val out3val out2val out1val 1 01010101 rw val =1 means valid 7fe0 inisoval input ep 8-15 valid in15val in14val in13val in12val in11val in10val in9val in8val 00000111 rw val =1 means valid 7fe1 outisoval output ep 8-15 valid out15val out14val out13val out12val out11val out10val out9val out8val 00000111 rw val =1 means valid 7fe2 fastxfr fast transfer mode fiso fblk rpol rmod1 rmod0 wpol wmod1 wmod0 xxxxxxxx rw 7fe3 autoptrh auto-pointer h a15 a14 a13 a12 a11 a10 a9 a8 xxxxxxxx rw 7fe4 autoptrl auto-pointer l a7 a6 a5 a4 a3 a2 a1 a0 xxxxxxxx rw 7fe5 autodata auto pointer data d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx rw 7fe6 (reserved) 7fe7 (reserved) setup data 7fe8 setupdat 8 bytes of setup data d7 d6 d5 d4 d3 d2 d1 d0 xxxxxxxx r isochronous fifo sizes 7ff0 out8addr endpt 8 out start addr a9 a8 a7 a6 a5 a4 0 0 xxxxxxxx rw 7ff1 out9addr endpt 9 out start addr a9 a8 a7 a6 a5 a4 0 0 xxxxxxxx rw 7ff2 out10addr endpt 10 out start addr a9 a8 a7 a6 a5 a4 0 0 xxxxxxxx rw 7ff3 out11addr endpt 11 out start addr a9 a8 a7 a6 a5 a4 0 0 xxxxxxxx rw 7ff4 out12addr endpt 12 out start addr a9 a8 a7 a6 a5 a4 0 0 xxxxxxxx rw 7ff5 out13addr endpt 13 out start addr a9 a8 a7 a6 a5 a4 0 0 xxxxxxxx rw 7ff6 out14addr endpt 14 out start addr a9 a8 a7 a6 a5 a4 0 0 xxxxxxxx rw 7ff7 out15addr endpt 15 out start addr a9 a8 a7 a6 a5 a4 0 0 xxxxxxxx rw 7ff8 in8addr endpt 8 in start addr a9 a8 a7 a6 a5 a4 0 0 xxxxxxxx rw 7ff9 in9addr endpt 9 in start addr a9 a8 a7 a6 a5 a4 0 0 xxxxxxxx rw 7ffa in19addr endpt 10 in start addr a9 a8 a7 a6 a5 a4 0 0 xxxxxxxx rw 7ffb in11addr endpt 11 in start addr a9 a8 a7 a6 a5 a4 0 0 xxxxxxxx rw 7ffc in12addr endpt 12 in start addr a9 a8 a7 a6 a5 a4 0 0 xxxxxxxx rw 7ffd in13addr endpt 13 in start addr a9 a8 a7 a6 a5 a4 0 0 xxxxxxxx rw 7ffe in14addr endpt 14 in start addr a9 a8 a7 a6 a5 a4 0 0 xxxxxxxx rw 7fff in15addr endpt 15 in start addr a9 a8 a7 a6 a5 a4 0 0 xxxxxxxx rw addr name description d7 d6 d5 d4 d3 d2 d1 d0 default cpu access notes


▲Up To Search▲   

 
Price & Availability of AN21XX

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X